Page 1 of 1

Automatic report of State switch

Posted: Fri Dec 07, 2018 1:37 am
by rrTea
Whenever I switch the main State, I like to print it in console too, just for confirmation, something simple like OnStart of a state:

Code: Select all

trace(NL + "...entering state_BattleG");
and OnLeave:

Code: Select all

trace("...leaving state_Report");
So this works perfectly but is a bit troublesome to maintain (for example if I change the name of the state I have to go to two different ZExpressions placed in two different nodes in the Project Tree and update it there too) and has some other drawbacks… Can this be automated to at least some extent? For example if I could make a component like this

Code: Select all

trace(NL + "...entering: " + StateSwitch.State);
and call this whenever needed (but obviously I can't get the string / name of the state like this) it'd be easier… But then again I would not be able to use this for leaving a State anyway, because I have to set the StateSwitch.State to "StateSwitch.State = null;" after each switch (so I can't know where it came from and I can't have the "now leaving" part).

So I don't have any better ideas how'd I set this up without overcomplicating such a simple task :) Is there some obvious way to go about it that I'm missing :)

Re: Automatic report of State switch

Posted: Fri Dec 07, 2018 12:16 pm
by VilleK
I thought you could use the IDE functions for this but seems I forgot to add "get" functions. I now added "getStringProperty" function. Please download again and the try attached script.

Re: Automatic report of State switch

Posted: Sat Dec 08, 2018 1:47 am
by rrTea
Aha! So that's how it's done! Excellent, thanks!

Re: Automatic report of State switch

Posted: Thu May 26, 2022 10:03 pm
by rrTea
I'm trying to use this to get the string property of a SetAppState named "setState_Branching".

Code: Select all

if	(DEBUG)
	{
	string s = getStringProperty(setState_Branching,"State");
	trace("Entering state: " + s);
  	}
But this gives me an error, "GetStringProperty called with prop of unsupported type: State". Am I doing something wrong or is this not meant to work to begin with?

Re: Automatic report of State switch

Posted: Fri May 27, 2022 7:30 am
by VilleK
I think you want to read the "Name" property, like this:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <AppState Name="AppState1"/>
    <SetAppState Name="SetAppState1" State="AppState1"/>
    <ZExpression>
      <Expression>
<![CDATA[if(DEBUG)	{
	string s = getStringProperty(SetAppState1.State,"Name");
	trace("Entering state: " + s);
}]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
</ZApplication>

Re: Automatic report of State switch

Posted: Fri May 27, 2022 4:56 pm
by rrTea
I see, I was using it wrongly! Thanks, this works!