[ZScript] Use variable as sprite name

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.

[ZScript] Use variable as sprite name

Postby 3saster » Tue Jan 15, 2019 6:57 pm

Is it possible to use a variable as a sprite name in ZScript? Something like
Code: Select allExpand view
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 allExpand view
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
3saster
 
Joined: 11 May 2018
Location: Canada

Re: [ZScript] Use variable as sprite name

Postby Pixel Eater » Tue Jan 15, 2019 10:54 pm

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 7 times

In this map when you 'use' the sink you can see your reflection change as you place your helmet there.
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: [ZScript] Use variable as sprite name

Postby 3saster » Tue Jan 15, 2019 11:23 pm

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 allExpand view
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
3saster
 
Joined: 11 May 2018
Location: Canada

Re: [ZScript] Use variable as sprite name

Postby Pixel Eater » Tue Jan 15, 2019 11:43 pm

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
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: [ZScript] Use variable as sprite name

Postby phantombeta » Tue Jan 15, 2019 11:49 pm

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.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support


Return to Scripting

Who is online

Users browsing this forum: No registered users and 3 guests