[ZScript]Allow converting String to StateLabel

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

[ZScript]Allow converting String to StateLabel

Postby FishyClockwork » Thu May 25, 2017 7:31 am

What the title says.

I'm attempting to check via ACS's ScriptCall function, which calls InStateSequence, to check if an actor is in a state sequence (such as 'Missile') in order to trigger certain events (like floors lowering/raising etc).
After an actor is found via ActorIterator I call (roughly)
Code: Select allExpand view
mo.InStateSequence(mo.curState, mo.FindState(x))

With 'mo' being the first thing ActorIterator finds and 'x' being the statelabel to find. I know ScriptCall doesn't accept statelabel as a variable type so I figured I'd pass a string instead. Unfortunately, I discovered it's impossible to convert a string into a statelabel. Even casting doesn't seem to work. I even tried to convert a name to statelabel but that doesn't work either.

Test example I tried with GZDoom 3.0.1 and GZDoom g3.0pre-225-gd633e8a
Code: Select allExpand view
version "2.5"
Class T : Actor
{
   void bleh()
   {
      string st = "konac";
      statelabel statlab = statelabel(st); //I get "Call to unknown function 'StateLabel'"
   }
}

And without casting I get "Cannot convert String to StateLabel"
User avatar
FishyClockwork
 
Joined: 23 Feb 2011

Re: [ZScript]Allow converting String to StateLabel

Postby Major Cooke » Thu May 25, 2017 9:58 am

Can't be done. StateLabels are just offsets, if memory serves me correctly. I tried suggesting this before myself, and Graf noped.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: [ZScript]Allow converting String to StateLabel

Postby FishyClockwork » Thu May 25, 2017 10:17 am

Well, worst case scenario I use a not-so-elegant workaround I already have in mind.
User avatar
FishyClockwork
 
Joined: 23 Feb 2011

Re: [ZScript]Allow converting String to StateLabel

Postby Graf Zahl » Thu May 25, 2017 11:01 am

It can be done but right now the code to do this at runtime is simply not present.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: [ZScript]Allow converting String to StateLabel

Postby Major Cooke » Thu May 25, 2017 11:17 am

Then I'm gonna hop aboard the "Yes please!" train. :mrgreen:
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: [ZScript]Allow converting String to StateLabel

Postby Major Cooke » Mon May 29, 2017 11:23 am

Say, Fishy, what was your workaround you had in mind? I'm actually now in need of something myself...

Code: Select allExpand view
List[ID_D4Pistol].ReadyState =       "D4Pistol.Ready";
List[ID_D4Pistol].FireState =       "D4Pistol.Fire";
List[ID_D4Pistol].AltFireState =    "D4Pistol.AltFire";
List[ID_D4Pistol].SelectState =    "D4Pistol.Select";
List[ID_D4Pistol].DeselectState =    "D4Pistol.Deselect";

List[ID_D4Shotgun].ReadyState =    "D4Shotgun.Ready";
List[ID_D4Shotgun].FireState =       "D4Shotgun.Fire";
List[ID_D4Shotgun].AltFireState =    "D4Shotgun.AltFire";
List[ID_D4Shotgun].SelectState =    "D4Shotgun.Select";
List[ID_D4Shotgun].DeselectState =    "D4Shotgun.Deselect";


Stuff like this is awful.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: [ZScript]Allow converting String to StateLabel

Postby FishyClockwork » Mon May 29, 2017 1:03 pm

Nothing too fancy or clever. And definitely nothing near as complex as what you're doing. :P
Code: Select allExpand view
      static const statelabel stlabels[] =
      {
         "Spawn", "See",
         "Melee", "Missile",
         "Pain", "Death",
         "XDeath", "Raise"
      };

These are all the state sequences I am checking/planning to check.
EDIT: I pass an integer value from ACS via the 'ScriptCall' function which matches the index of the array.
User avatar
FishyClockwork
 
Joined: 23 Feb 2011

Re: [ZScript]Allow converting String to StateLabel

Postby Major Cooke » Mon May 29, 2017 1:23 pm

Once this happens, my akimbo system will become a lot easier to deal with. I'm quite excited for it.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: [ZScript]Allow converting String to StateLabel

Postby Player701 » Mon Oct 15, 2018 7:16 am

Sorry for the bump, just wanted to say that I too would find this very useful if this were implemented, as I have a use case very similar to this one (using formatted strings), where a lot of unnecessary code could be removed if this feature existed.
User avatar
Player701
 
 
 
Joined: 13 May 2009
Location: Russia
Discord: Player701#8214
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: [ZScript]Allow converting String to StateLabel

Postby Warden » Sun Feb 28, 2021 10:39 am

It would be nice to be able to resolve ternaries. Something like this throws a cannot convert string to StateLabel error and I wind up going back to magic number offsets.

Code: Select allExpand view
Fire:
        PLSR C 1 Bright A_FirePlasma;
        PLSR CC 1 Bright;
        TNT1 A 0 A_ReFire(random(0, 1) ? "FireAlt1" : "FireAlt2");
        goto Cooldown;
Warden
 
Joined: 24 May 2020

Re: [ZScript]Allow converting String to StateLabel

Postby Graf Zahl » Sun Feb 28, 2021 10:55 am

Does it work if you cast the single strings? The main problem here is that even in the best case it cannot be resolved at compile time and would cause quite a bit of overhead, even if the conversion was added.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests