[ZScript] Use variable as sprite name

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!)
Post Reply
User avatar
3saster
Posts: 199
Joined: Fri May 11, 2018 2:39 pm
Location: Canada

[ZScript] Use variable as sprite name

Post 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;
    }
}
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: [ZScript] Use variable as sprite name

Post 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.
User avatar
3saster
Posts: 199
Joined: Fri May 11, 2018 2:39 pm
Location: Canada

Re: [ZScript] Use variable as sprite name

Post 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?
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: [ZScript] Use variable as sprite name

Post 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).
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [ZScript] Use variable as sprite name

Post 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.
Post Reply

Return to “Scripting”