[ZScript]Allow converting String to StateLabel

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

Moderator: GZDoom Developers

User avatar
Fishytza
Posts: 788
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: No Preference

[ZScript]Allow converting String to StateLabel

Post by Fishytza »

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 all

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 all

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
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript]Allow converting String to StateLabel

Post by Major Cooke »

Can't be done. StateLabels are just offsets, if memory serves me correctly. I tried suggesting this before myself, and Graf noped.
User avatar
Fishytza
Posts: 788
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: No Preference

Re: [ZScript]Allow converting String to StateLabel

Post by Fishytza »

Well, worst case scenario I use a not-so-elegant workaround I already have in mind.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49183
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript]Allow converting String to StateLabel

Post by Graf Zahl »

It can be done but right now the code to do this at runtime is simply not present.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript]Allow converting String to StateLabel

Post by Major Cooke »

Then I'm gonna hop aboard the "Yes please!" train. :mrgreen:
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript]Allow converting String to StateLabel

Post by Major Cooke »

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

Code: Select all

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
Fishytza
Posts: 788
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: No Preference

Re: [ZScript]Allow converting String to StateLabel

Post by Fishytza »

Nothing too fancy or clever. And definitely nothing near as complex as what you're doing. :P

Code: Select all

		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
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: [ZScript]Allow converting String to StateLabel

Post by Major Cooke »

Once this happens, my akimbo system will become a lot easier to deal with. I'm quite excited for it.
User avatar
Player701
 
 
Posts: 1684
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support

Re: [ZScript]Allow converting String to StateLabel

Post by Player701 »

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.
Warden
Posts: 42
Joined: Sun May 24, 2020 11:06 am

Re: [ZScript]Allow converting String to StateLabel

Post by Warden »

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 all

Fire:
        PLSR C 1 Bright A_FirePlasma;
        PLSR CC 1 Bright;
        TNT1 A 0 A_ReFire(random(0, 1) ? "FireAlt1" : "FireAlt2");
        goto Cooldown;
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49183
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript]Allow converting String to StateLabel

Post by Graf Zahl »

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.

Return to “Feature Suggestions [GZDoom]”