ZScript Discussion

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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!)
User avatar
Rachael
Posts: 13635
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: ZScript Discussion

Post by Rachael »

Nash wrote:My general advice to everyone: stop being scared and just write your first simple ZScript actor. The syntax isn't that much different from DECORATE, you just have to adhere to the new format (like adding semicolons etc, which is already written on the wiki).
I had to do that when Graf removed native support from DECORATE - pretty sure GZDoom's light actors would've stopped working, so I figured I might as well convert them to ZScript. :P Surprisingly, it worked well on the very first try.
Last edited by Rachael on Thu Dec 01, 2016 1:30 pm, edited 1 time in total.
User avatar
Zanieon
Posts: 2059
Joined: Tue Jan 13, 2009 4:13 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Somewhere in the future

Re: ZScript Discussion

Post by Zanieon »

Well i'm not going to touch ZScript until Zandronum also adopts it despite me wanting to convert my mod to it to nullify some ACS/DECORATE trickery, but this will take its time to be done so until there...

And from what i'm seeing this resembles Unreal Script so, it is not being hard to me interpret the examples given in the wiki already.
User avatar
Major Cooke
Posts: 8190
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

And if I recall correctly, Unreal Script is what Randi wanted it to look like from the get-go. Kinda. :P
User avatar
Nash
 
 
Posts: 17452
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript Discussion

Post by Nash »

The ZDoom community is very good with self-documentation. Just look at how detailed the wiki is today. I can tell you, as a person who's been here from the start (more or less), the ZDoom wiki started out very bare and empty compared to what you see today.

I'd say the quality of information available on the ZDoom wiki is on par with the bigger wikis like Unreal Engine 4's. Have faith in the community... before long, everything related to ZScript will be detailed in the wiki. It naturally will be, due to how active the ZDoom community is.
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: ZScript Discussion

Post by D2JK »

I have a script that occasionally increases player's spawnhealth, but GetSpawnHealth() seems to ignore this incrementation. In this case, do I have to return to calling an ACS script that returns the proper value, or is there a way to do this in ZScript?
User avatar
Player701
 
 
Posts: 1649
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: ZScript Discussion

Post by Player701 »

I should probably agree that the following code should not compile:

Code: Select all

class Test : Actor
{
  State A_Test()
  {
    bool x = true;
    return ResolveState(x ? "Test" : null);
  }
}
and indeed it doesn't:

Code: Select all

Incompatible types for ?: operator
However, the following one also fails:

Code: Select all

class Test : Actor
{
  State A_Test()
  {
    bool x = true;
    return ResolveState(x ? "Test1" : "Test2");
  }
}

Code: Select all

Cannot convert String to StateLabel
Eh?

Let's try something simpler:

Code: Select all

class Test : Actor
{
  State A_Test()
  {
    return ResolveState("Test");
  }
}
Success!

I can draw the following conclusion from this: apparently, the literal passed to ResolveState walks like a string and quacks like a string but it is not really a string. This is quite surprising indeed.
Blue Shadow
Posts: 4964
Joined: Sun Nov 14, 2010 12:59 am

Re: ZScript Discussion

Post by Blue Shadow »

D2JK wrote:I have a script that occasionally increases player's spawnhealth, but GetSpawnHealth() seems to ignore this incrementation. In this case, do I have to return to calling an ACS script that returns the proper value, or is there a way to do this in ZScript?
Try GetMaxHealth(). Keep in mind though that this function is native to the PlayerPawn class, not the Actor class. So you might need to do some casting.
User avatar
kodi
 
 
Posts: 1355
Joined: Mon May 06, 2013 8:02 am

Re: ZScript Discussion

Post by kodi »

This gives me an error:
Activation THINGSPEC_ThingTargets| THINGSPEC_ThingActs|THINGSPEC_NoDeathSpecial|THINGSPEC_Switch;
"THINGSPEC_Switch" is apparently an unknown identifier. If I comment just that one out it loads properly.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49098
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

Yes, someone only added them to the DECORATE parser but not to the constant table.
User avatar
Major Cooke
Posts: 8190
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

So I'm trying to change a var via CustomInventory's use state:

Code: Select all

			MyPlayer plr = MyPlayer(Owner);
			if (plr && plr.CheckClass("MyPlayer"))
			{
				plr.user_chasecam = 0;
				plr.user_cc = 0;
			}
But it keeps complaining about abortions (no pun intended). How do I do this properly?
Blue Shadow
Posts: 4964
Joined: Sun Nov 14, 2010 12:59 am

Re: ZScript Discussion

Post by Blue Shadow »

In the casting bit, would using self instead of Owner work?
User avatar
Major Cooke
Posts: 8190
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: ZScript Discussion

Post by Major Cooke »

Huh... That actually worked. But that's also kinda screwy, when the owner is supposed to be doable... Graf, any explanation for this?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49098
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

Custom inventory state chains, like weapons run in the context of the item's owner. So this is normal behavior.
User avatar
MaxED
Posts: 2246
Joined: Tue Feb 28, 2012 12:55 pm

Re: ZScript Discussion

Post by MaxED »

zdoom.wiki wrote:ZScript lump can include the names of other lumps for processing similar to DECORATE, but no #include word is used.
Is there any particular reason why you
1. introduce inconsistency (DECORATE, ACS, GLDEFS, SBARINFO and probably some other text lumps use #include).
2. make the life of editing tools programmers harder. To parse "regular" #include, all you have to do is to look for "#include" token and use the word right after it. To parse ZScript include, you'll need to recognize all top level ZScript keywords (such as "class", "struct", "enum", "const", "#define", "extend" etc.) and also update the parser when new top level keywords are introduced.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49098
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript Discussion

Post by Graf Zahl »

Because the grammar cannot recursively include other lumps. For that it'd need a full preprocessor.
This is a spot that definitely needs some work. I don't like it either but so far it was ok for testing this stuff. It's also one of the main reasons why I haven't merged it yet. This definitely needs a proper fix before going officially public.

Return to “Scripting”