[ZScript]Allow converting String to StateLabel

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is ON
[img] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: [ZScript]Allow converting String to StateLabel

Re: [ZScript]Allow converting String to StateLabel

by 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.

Re: [ZScript]Allow converting String to StateLabel

by 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 all

Fire:
        PLSR C 1 Bright A_FirePlasma;
        PLSR CC 1 Bright;
        TNT1 A 0 A_ReFire(random(0, 1) ? "FireAlt1" : "FireAlt2");
        goto Cooldown;

Re: [ZScript]Allow converting String to StateLabel

by 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.

Re: [ZScript]Allow converting String to StateLabel

by 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.

Re: [ZScript]Allow converting String to StateLabel

by Fishytza » 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 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.

Re: [ZScript]Allow converting String to StateLabel

by 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 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.

Re: [ZScript]Allow converting String to StateLabel

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

Then I'm gonna hop aboard the "Yes please!" train. :mrgreen:

Re: [ZScript]Allow converting String to StateLabel

by 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.

Re: [ZScript]Allow converting String to StateLabel

by Fishytza » Thu May 25, 2017 10:17 am

Well, worst case scenario I use a not-so-elegant workaround I already have in mind.

Re: [ZScript]Allow converting String to StateLabel

by 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.

[ZScript]Allow converting String to StateLabel

by Fishytza » 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 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"

Top