Page 1 of 1

[ZScript] Use variable as sprite name

Posted: Tue Jan 15, 2019 5:57 pm
by 3saster
Is it possible to use a variable as a sprite name in ZScript? Something like

Code: Select all

Class GreenChaingunGuy : ChaingunGuy
{
    String name = "GPOS";
    states
    {
    Spawn:
        "name" AB 10 A_Look
        Loop
    }
}
Or even better, can it replace names in an inherited actor's states? Like

Code: Select all

Class GreenChaingunGuy : ChaingunGuy
{
    String name = "GPOS";
    states
    {
    Spawn:
        TNT1 A 0 { Treat "CPOS" sprite name as if it was name };
    //This...
        goto Super::Spawn;
    //...should be the same as this
    SpawnLoop:
        GPOS AB 10 A_Look;
        goto SpawnLoop;
    }
}

Re: [ZScript] Use variable as sprite name

Posted: Tue Jan 15, 2019 9:54 pm
by Pixel Eater
If you set the sprite index to #### you can then change it with the actor's .sprite property.

An example:
SinK.pk3
(59.76 KiB) Downloaded 81 times
In this map when you 'use' the sink you can see your reflection change as you place your helmet there.

Re: [ZScript] Use variable as sprite name

Posted: Tue Jan 15, 2019 10:23 pm
by 3saster
Nice! Exactly what I was looking for.

With that being said, is there a way to do it with a pre-existing actor to overwrite a specific instance of the name? I know in DeHacked you could do something like

Code: Select all

text 4 4
CPOSGPOS
but obviously, this affects any actor with CPOS sprites. Is there a way to do something like this in ZScript local to an actor?

Re: [ZScript] Use variable as sprite name

Posted: Tue Jan 15, 2019 10:43 pm
by Pixel Eater
I think all you can do is inherit from an existing actor, then copy and change the original's states definition into the duplicate's ZScript block. Though Graf may be cooking up something currently which would allow us to alter actors without replacing them (unless I've misunderstood).

Re: [ZScript] Use variable as sprite name

Posted: Tue Jan 15, 2019 10:49 pm
by phantombeta
Pixel Eater wrote:Though Graf may be cooking up something currently which would allow us to alter actors without replacing them (unless I've misunderstood).
It won't allow you to alter them, no - it'll just allow you to add new variables, functions, constants, etc. to them.