Page 9 of 9

Re: stateful.lua

Posted: Thu Jun 12, 2014 3:59 pm
by SiENcE
@kikito : I have another problem with stateful. Maybe a bug, maybe design decision. I hope you can help :).

When i stack states and use gotoState() in a stacked state, the 'exitedState' function is only called for the stacked state and not all, down to root state. I thought goto calls all 'exitedState' from all states i have stacked via push.

Sample
- 'MainMenu'
push 'LevelMenu' -> here i call gotoState 'InGame' and this only calls LevelMenu:exitedState() and not also MainMenu:exitedState()

Re: stateful.lua

Posted: Thu Jun 12, 2014 5:20 pm
by kikito
Thanks for reporting this. I will give it a look.

EDIT: It is now fixed on github. I have made some other small changes and released version 1.0.2

Re: stateful.lua

Posted: Fri Jun 13, 2014 8:44 am
by SiENcE
Thanks for fixing this!

Re: stateful.lua

Posted: Fri Jun 13, 2014 1:47 pm
by kikito
My pleasure, thank you for helping me make the library better!

Re: stateful.lua

Posted: Tue Jun 17, 2014 7:55 am
by gestaltist
Hi kikito.

I am having a hard time understanding how and when to use state popping and pushing. I am always using “gotoState”. I would be grateful for an explanation

Re: stateful.lua

Posted: Tue Jun 17, 2014 11:09 am
by kikito
Hi!

I copied the state stacking mechanics form unrealscript. To this day, I have never needed it. When I thought I needed it, I ended up finding a better solution without stacking or even without state.

I consider gotoState is the general, usual case. Using the state stack is much, much less frequent; an "edge case", if you will. If you use a stack, it is doubtful that you will need more than 1 level.

The use case is: you have a "general state", and a state which acts as a "complement". The complement acts like a "sub state", modifying some methods of the base state.

You can find examples of most of the methods on my libraries in the /spec/ folder. These are tests that make sure that each method works as expected, but they also work as documentation. There's a test for state stacking:

https://github.com/kikito/stateful.lua/ ... ec.lua#L93

Admittedly, the state names are not great - because thinking about ideal places where state stacking makes sense is difficult for me. After all, it's a feature I never use myself. But the guys who made unrealscript are more intelligent than me, so they probably had good reasons to add it.

Sorry if my answer is a bit lackluster; it's a feature that I never use.

Re: stateful.lua

Posted: Tue Jun 17, 2014 11:39 am
by gestaltist
Thanks kikito. That piece of code was very informative.

Now that I think about it, this kind of state stacking might be useful for manipulating NPC AI.

But you never using the feature has kind of confirmed my suspicions, as well.

If I may suggest something, you could link to this thread from stateful’s GitHub page. It answers a lot of questions I had after browsing the code and using the library.

Re: stateful.lua

Posted: Wed Jun 18, 2014 12:55 pm
by SiENcE
I use stacking for a pause menu above the main game state.

Re: stateful.lua

Posted: Wed Jun 18, 2014 2:37 pm
by kikito
Yes, that definitely could be a use case. Thanks for mentioning it.