@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()
stateful.lua
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: stateful.lua
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
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.
Re: stateful.lua
Thanks for fixing this!
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: stateful.lua
My pleasure, thank you for helping me make the library better!
When I write def I mean function.
-
- Prole
- Posts: 49
- Joined: Thu May 29, 2014 10:56 am
Re: stateful.lua
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
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
--
My OOP implementation:
https://github.com/stefanstr/class-by-gestaltist.git
My dungeon / tiled map generator:
https://github.com/stefanstr/lua_maps_by_gestaltist
My Love2D experiments:
https://github.com/stefanstr/Small-Love2D-Projects
My OOP implementation:
https://github.com/stefanstr/class-by-gestaltist.git
My dungeon / tiled map generator:
https://github.com/stefanstr/lua_maps_by_gestaltist
My Love2D experiments:
https://github.com/stefanstr/Small-Love2D-Projects
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: stateful.lua
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.
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.
-
- Prole
- Posts: 49
- Joined: Thu May 29, 2014 10:56 am
Re: stateful.lua
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.
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.
--
My OOP implementation:
https://github.com/stefanstr/class-by-gestaltist.git
My dungeon / tiled map generator:
https://github.com/stefanstr/lua_maps_by_gestaltist
My Love2D experiments:
https://github.com/stefanstr/Small-Love2D-Projects
My OOP implementation:
https://github.com/stefanstr/class-by-gestaltist.git
My dungeon / tiled map generator:
https://github.com/stefanstr/lua_maps_by_gestaltist
My Love2D experiments:
https://github.com/stefanstr/Small-Love2D-Projects
Re: stateful.lua
I use stacking for a pause menu above the main game state.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: stateful.lua
Yes, that definitely could be a use case. Thanks for mentioning it.
When I write def I mean function.
Who is online
Users browsing this forum: No registered users and 2 guests