"How do I ZScript?"

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Locked
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: "How do I ZScript?"

Post by Major Cooke »

User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: "How do I ZScript?"

Post by hideousdestructor »

Does ShrinkToFit delete entries that are zero, or do they have to be totally empty?

What would be the best way to preserve a dynamic array between maps?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

ShrinkToFit reallocates the memory buffer to hold the exact amount of entries used. To avoid fequent reallocation the array class reallocates in larger chunks, this is for freeing that unused space once you know the array won't grow any further.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: "How do I ZScript?"

Post by ZZYZX »

When you want to declare an array field, do you write "type[arraylen] field" or "type field[arraylen]"? Or both are ok? Because usually it's written like the latter, but Gutawer wrote this:

Code: Select all

string[2] stringArray;
And it broke in GZDB, while didn't break in GZDoom.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Both are valid syntax. This also works:

Code: Select all

String[2] messages[5];
User avatar
krokots
Posts: 298
Joined: Tue Jan 19, 2010 5:07 pm

Re: "How do I ZScript?"

Post by krokots »

How to change the damage of projectiles from a variable that is stored inside a monster?

Let me explain. For instance, i got two imps. Both have "user_damage" int (3) and in A_CustomComboAttack the damage is calculated: random(1,8)*user_damage. But it will only work for melee. I want this variable to apply to projectiles that this imps fire. How to do this?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

In DECORATE it's not possible, but in ZScript you can define a damage function that accesses the variables of the projectile's shooter.
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: "How do I ZScript?"

Post by Gutawer »

So dynamic arrays are in now, is it possible to pass one to a function? I still get the "Invalid type Type for function parameter" error when using one as a function argument.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: "How do I ZScript?"

Post by Major Cooke »

No, not yet. But you can pass in a pointer to the function, have it get the actor cast and, if the array's local (not inside the states) you can perform Copy from within the function.
Last edited by Major Cooke on Sat Feb 11, 2017 8:49 am, edited 1 time in total.
User avatar
krokots
Posts: 298
Joined: Tue Jan 19, 2010 5:07 pm

Re: "How do I ZScript?"

Post by krokots »

Graf Zahl wrote:In DECORATE it's not possible, but in ZScript you can define a damage function that accesses the variables of the projectile's shooter.
Something like this:
Imp:

Code: Select all

class DoomImp : Actor
{
int user_damage
...
Imp Ball:

Code: Select all

...
DamageFunction (random(1,8)*target.user_damage);
...
gives error (Unknown identifier)
It must be a property or something?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: "How do I ZScript?"

Post by Major Cooke »

That's not what he meant.

Assuming you have a unique class and not trying to inject it on DoomImp... He meant, you can make your own type of damage function, not the property.

Code: Select all

void MyBallExplode()
{
    int dmg = damage;
    let dimp = MyDoomImp(target);
    if (dimp) dmg = dimp.user_damage;
    if (tracer) tracer.DamageMobj(self, target, dmg);
}
Give the projectile +HITTRACER flag, then upon entering the death state, have it do this:

Code: Select all

TNT1 A 0 MyBallExplode();
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: "How do I ZScript?"

Post by ZZYZX »

Graf Zahl wrote:Both are valid syntax. This also works:

Code: Select all

String[2] messages[5];
What does it do? Is it a string messages[5][2] or 5 overrides the 2?
Also can there be multiple indices as in multiple dimensions?
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: "How do I ZScript?"

Post by Nash »

Help, if I know the TID of the thing, can I do anything useful to the thing with the TID? And yes this is a ZScript question. I want to make a thing that - when you shoot at it - it finds out the Vector3 position of something with a specific TID.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

Major Cooke wrote:No, not yet. But you can pass in a pointer to the function, have it get the actor cast and, if the array's local (not inside the states) you can perform Copy from within the function.

For now, if you absolutely have to, wrap the array into a struct and pass that around. Struct references can be passed to functions, even if they contain data that otherwise can not.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: "How do I ZScript?"

Post by Graf Zahl »

ZZYZX wrote:
Graf Zahl wrote:Both are valid syntax. This also works:

Code: Select all

String[2] messages[5];
What does it do? Is it a string messages[5][2] or 5 overrides the 2?
Also can there be multiple indices as in multiple dimensions?
That's the same as String[2][5] messages or String messages[2][5];
Locked

Return to “Scripting”