Automatic report of State switch

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Automatic report of State switch

Post 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 :)
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Automatic report of State switch

Post 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.
Attachments
ShowState.zgeproj
(755 Bytes) Downloaded 489 times
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Automatic report of State switch

Post by rrTea »

Aha! So that's how it's done! Excellent, thanks!
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Automatic report of State switch

Post 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?
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Automatic report of State switch

Post 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>
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: Automatic report of State switch

Post by rrTea »

I see, I was using it wrongly! Thanks, this works!
Post Reply