stateful.lua

Showcase your libraries, tools and other projects that help your fellow love users.
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 »

:D

Stateful is updated to 1.0.1 . The two bugs I found:
  • A couple typos on the error messages
  • When you where on state A and pushed state B on top of it, both A:exitedState and A:pausedState were called. That was a mistake. On the new version, only A:pausedState is called. You may have to adapt your code if you push and pop states and rely on exitedState.
Regarding the bug on the demo, here is a hint: while you are on one of the Non-Implemented states (for example after pressing "Play"), try clicking on the screen, where the menu is. Do you know why this happens? Do you know how to solve it? (I do)
When I write def I mean function.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: stateful.lua

Post by TechnoCat »

kikito wrote:Regarding the bug on the demo, here is a hint: while you are on one of the Non-Implemented states (for example after pressing "Play"), try clicking on the screen, where the menu is. Do you know why this happens? Do you know how to solve it? (I do)
Is it because you aren't overriding mousepressed when you push the NotImplemented state?

I also must ask: Why are you returning your gamestates? Your requires aren't assigning the returns.
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 »

TechnoCat wrote:Is it because you aren't overriding mousepressed when you push the NotImplemented state?
Correct! You won! :D
TechnoCat wrote:I also must ask: Why are you returning your gamestates? Your requires aren't assigning the returns.
I actually needed to use them once: in OptionsMenu I needed MainMenu so it could inherit. I didn't want to make the states public, so I made MainMenu return the state (OptionsMenu requires it). Since I was doing it in one file, it made sense to make it in all files. I didn't know which ones would also need it.

Another option would have been sticking the gamestates inside Game (Game.MainMenu, Game.NotImplemented, etc) or making the states globals.
When I write def I mean function.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: stateful.lua

Post by TechnoCat »

kikito wrote:
TechnoCat wrote:Is it because you aren't overriding mousepressed when you push the NotImplemented state?
Correct! You won! :D
Huzzah!
Image
c00ld00d
Prole
Posts: 5
Joined: Wed Jan 18, 2012 6:56 am

Re: stateful.lua

Post by c00ld00d »

Kikito,

you're my hero :).
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 »

@technocat: LOL

@c00ld00d thank you! Let me know if you need more explanation on the menus. I think it's quite straightforward, though.
When I write def I mean function.
User avatar
Mr.Smith
Prole
Posts: 9
Joined: Wed Mar 28, 2012 8:04 am

Re: stateful.lua

Post by Mr.Smith »

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

GameState renders the map itself and PlayState and EditorState must be pushed ot top of GameState to render enemies and towers,edit maps respectively.
But if i push this states on top of GameState they will override methods of GameState. How can i call both the methods of GameState and PlayState/EditorState?
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: stateful.lua

Post by rokit boy »

I really wan't to use this but I would really like the classes to be Slither style D:
u wot m8
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 »

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 :shock: 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.
When I write def I mean function.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: stateful.lua

Post by rokit boy »

I learnt how to use slither and I use it for every project I make from now on. I just find it hard to use that class system and making other projects with slither.
u wot m8
Post Reply

Who is online

Users browsing this forum: No registered users and 78 guests