"How do I ZScript?"
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!)
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!)
- 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:
- 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?"
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?
What would be the best way to preserve a dynamic array between maps?
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
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.
Re: "How do I ZScript?"
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:And it broke in GZDB, while didn't break in GZDoom.
Code: Select all
string[2] stringArray;- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
Both are valid syntax. This also works:
Code: Select all
String[2] messages[5];
Re: "How do I ZScript?"
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?
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?
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
In DECORATE it's not possible, but in ZScript you can define a damage function that accesses the variables of the projectile's shooter.
Re: "How do I ZScript?"
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.
- 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?"
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.
Re: "How do I ZScript?"
Something like this: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.
Imp:
Code: Select all
class DoomImp : Actor
{
int user_damage
...Code: Select all
...
DamageFunction (random(1,8)*target.user_damage);
...
It must be a property or something?
- 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?"
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.
Give the projectile +HITTRACER flag, then upon entering the death state, have it do this:
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);
}Code: Select all
TNT1 A 0 MyBallExplode();Re: "How do I ZScript?"
What does it do? Is it a string messages[5][2] or 5 overrides the 2?Graf Zahl wrote:Both are valid syntax. This also works:
Code: Select all
String[2] messages[5];
Also can there be multiple indices as in multiple dimensions?
Re: "How do I ZScript?"
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.
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
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.
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
That's the same as String[2][5] messages or String messages[2][5];ZZYZX wrote:What does it do? Is it a string messages[5][2] or 5 overrides the 2?Graf Zahl wrote:Both are valid syntax. This also works:
Code: Select all
String[2] messages[5];
Also can there be multiple indices as in multiple dimensions?
