stateful.lua

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: stateful.lua

Post 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()
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: stateful.lua

Post 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
When I write def I mean function.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: stateful.lua

Post by SiENcE »

Thanks for fixing this!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: stateful.lua

Post by kikito »

My pleasure, thank you for helping me make the library better!
When I write def I mean function.
gestaltist
Prole
Posts: 49
Joined: Thu May 29, 2014 10:56 am

Re: stateful.lua

Post 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
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: stateful.lua

Post 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.
When I write def I mean function.
gestaltist
Prole
Posts: 49
Joined: Thu May 29, 2014 10:56 am

Re: stateful.lua

Post 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.
User avatar
SiENcE
Party member
Posts: 792
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: stateful.lua

Post by SiENcE »

I use stacking for a pause menu above the main game state.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: stateful.lua

Post by kikito »

Yes, that definitely could be a use case. Thanks for mentioning it.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 205 guests