rokit boy wrote:I really wan't to use this but I would really like the classes to be Slither style D:
Please take no offense, rokit, but I think you might want to consider sticking with the basics for a while instead. You are barely walking ... and this is a bit like doing somersaults.
Mr.Smith wrote:Hi Kikito!
I'm trying to make tower defense and i have the following structure of states:
App:include('Stateful')
|-App:addState('GameState')
| |-App:addState('PlayState')
| |-App:addState('EditorState')
|-App:addState('Menu')
|-App:addState('Option')
|etc
I didn't realize that this question was here until rokit boy posted
Sorry!
Let me answer just in case it's still useful.
First of all, you can't add "substates" in Stateful - this is done in purpose. However, you still have plenty of options without those.
First option is: Simply don't use a GameState state.
Code: Select all
App:include('Stateful')
|-App:addState('PlayState')
|-App:addState('EditorState')
|-App:addState('Menu')
|-App:addState('Option')
This is the easiest thing to implement, and is the one I recommend you.
... except in one case: if you end up needing functionality to be "shared" across those two states, and those states only (i.e. it doesn't make sense to put in on the "non-stateful" part of App).
If you have duplicated functionality in PlayState and EditorState, divide the functionality into methods, until you have the parts that are equal and the parts that are different into different methods. Then choose one state to be the "parent". The "children" will "override" those methods.There are two ways to do this: state inheritance and using the state pile.
Assuming that the "parent" was PlayState, you can make EditorState "inherit" from it by including it as a second parameter to addState:
Code: Select all
App:addState('PlayState')
...
App:addState('EditorState', PlayState) -- EditorState inherits all PlayState methods. You can override them
The last option is making EditorState "push" and "pop" over PlayState, more or less like you imagined. You would have to have the code prepared in the same way: methods should be overridable.