ZScript Discussion

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!)
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: ZScript Discussion

Post by Graf Zahl »

I think the problem is fixed. (that is, the software side of it) Some tildes in &= ~flag assignments were missing.
Unfortunately it's a hardware problem. The key combination to produce the tilde character does not work right anymore on my computer. I guess I need a new keyboard.

Aside from that: @Nash: You GetClass checks are dead wrong! Either you test the pointer against null or don't test at all. Class types will always error out if you try to specify a non-existent class, if you have the pointer initialized it will always be valid. Running GetClass on a null pointer is a crashable offense, on the other hand.
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

Re: ZScript Discussion

Post by Major Cooke »

For this recent commits with the states, does this allow us to grab the name of the state the actor is currently in? Looks like it. I'm assuming it's a StateLabel type?
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

Re: ZScript Discussion

Post by Major Cooke »

D2JK wrote:Strangely, I couldn't get "chance" to work at all, even though the wiki is correct on that one.
That's because it's 'failchance'.
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: ZScript Discussion

Post by Graf Zahl »

No. The actor is never 'in' a state. It is not possible to get a label from a state.
And the StateLabel type is not for retrieving labels but for storing state labels independently of the current actor.
It was added because the previous implementation did not have any concept of a state label at all. When it found a string in a state context it got translated within the context of the actor it was used in, causing massive problems if it was supposed to be used on another actor (e.g. the target or tracer.) By storing state labels as a dedicated type they can be passed around between functions and be resolved where they are actually needed.
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: ZScript Discussion

Post by Graf Zahl »

Major Cooke wrote:
D2JK wrote:Strangely, I couldn't get "chance" to work at all, even though the wiki is correct on that one.
That's because it's 'failchance'.

OK. Someone really needs to go through the list and review the argument names for both clarity and consistency. Any volunteers?
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

Re: ZScript Discussion

Post by Major Cooke »

I'm working on it now, but I notice there's a span of commonly used names that were changed around. I'm wondering if Gez can somehow perform a mass find and replace in the wiki...

I.e. sound 'soundname' has been changed to 'whattoplay' in a lot of places.
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: ZScript Discussion

Post by Graf Zahl »

With 'reviewin' I mean to check both sides and fix the one where the names are not good. Keep in mind that for non-optional parameters this is not even relevant.
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

Re: ZScript Discussion

Post by Major Cooke »

Not to mention the first optional after the required parameters. Huh...
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: ZScript Discussion

Post by Graf Zahl »

It may also make sense to change the description. This bracket madness is not helpful, especially since with named parameters they imply something that's no longer valid.
Better have the argument list as it appears in the script definitions, including the default values as-is.
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

Re: ZScript Discussion

Post by Major Cooke »

Gez? Could use your help here!

Hmm... This does make me wonder though, should we have the wiki examples as flags: 0 or flags = 0? For the sake of zscript.
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: ZScript Discussion

Post by Graf Zahl »

flags: 0 is a named parameter
flags = 0 is a parameter declaration with a default value.
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: ZScript Discussion

Post by Blue Shadow »

Is there currently a way to access an actor pointer's local variable? Here a simple example of what I'm trying to do:

Code: Select all

class ThingA : Actor
{
    int user_cflags;

    States
    {
    Spawn:
        SOUL A -1 Bright NoDelay
        {
            user_cflags = 16;
            A_SpawnItemEx("ThingB", 0, 64.0, 0, 0, 0, 0, 0, SXF_SETMASTER);
        }
        Stop;
    }
}

class ThingB : Actor
{
    States
    {
    Spawn:
        SOUL A -1 Bright NoDelay
        {
            if(master)
            {
                A_LogInt(master.user_cflags);
            }
        }
        Stop;
    }
}
That produces an error: "Unknown identifier 'user_cflags'".
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: ZScript Discussion

Post by Graf Zahl »

Yes, but you need to cast master to a proper type that contains the variable in question. (and check if the cast was successful, in case the type did not match)
'master' is of type Actor and this type does not have a field named 'user_cflags'.

And in case you ask: If you want to do this with unrelated classes, A_GetUserVar is the only way to do it, any language that apparently can do such a thing natively is just hiding a similar function behind it.
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

Re: ZScript Discussion

Post by Major Cooke »

Graf Zahl wrote:And in case you ask: If you want to do this with unrelated classes, A_GetUserVar is the only way to do it, any language that apparently can do such a thing natively is just hiding a similar function behind it.
That would be of immense help. This will keep things nice and sane at least and reduce all the code needed to perform it properly, especially if there's a bunch of inheriting actors that have it. It would allow overall encapsulation and dramatic reduction of bloat.
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: ZScript Discussion

Post by Graf Zahl »

I won't even consider such an approach, because it's slow down the VM quite considerably. Instead of a static lookup for a member field you have to call a time consuming search function each time, and you never really can tell when it is needed and when not so you have to do it always. Don't ask me how Javascript solves this problem, but it's either slow or a memory waster.

It´s also one of the features in Javascript which drove me up walls, because it eliminates all options for compile time checks for errors and encourages sloppy coding. The result is inevitably broken code that's hard to debug.

This is also why I forced the 'override' keyword on virtual overrides, it may look redundant but is a major asset in finding scripting errors because it allows compile time checks where otherwise the program would compile but then fail at runtime with strange behavior.

Return to “Scripting”