Automatic report of State switch

All topics about ZGameEditor goes here.

Moderator: Moderators

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

Automatic report of State switch

Post by rrTea » Fri Dec 07, 2018 1:37 am

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: 1989
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Automatic report of State switch

Post by VilleK » Fri Dec 07, 2018 12:16 pm

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
(784 Bytes) Downloaded 39 times

User avatar
rrTea
Posts: 361
Joined: Sat Feb 15, 2014 9:54 am

Re: Automatic report of State switch

Post by rrTea » Sat Dec 08, 2018 1:47 am

Aha! So that's how it's done! Excellent, thanks!

Post Reply