hekailiang / squirrel

squirrel-foundation is a State Machine library, which provided a lightweight, easy use, type safe and programmable state machine implementation for Java.
http://hekailiang.github.io/squirrel/
Other
2.19k stars 540 forks source link

Events with parameters? #55

Closed jordillonch closed 8 years ago

jordillonch commented 8 years ago

Is there some way of use events that bring some parameters? All examples that I found in the code are just events that are enums. Thanks!

hekailiang commented 8 years ago

What do you mean events bring some parameters? Could you give me an example and let me know why you need this?

jordillonch commented 8 years ago

I mean to carry some data with the event. For example I am thinking in an event like "join player" and I would like to get the "player id" from the event.

hekailiang commented 8 years ago

I think you can put this kind of parameters in Context object, which means fire an event like "JOIN_PLAYER" with context "player_id".

jordillonch commented 8 years ago

Yes but I want to use the context as a game state as it is done in your snake example.

hekailiang commented 8 years ago

Then you can compose a game state and the parameter as the Context object.

jordillonch commented 8 years ago

Yes, I see. But I think may be it's more clear to put data related with the event in the same even. Anyway, thanks for your answers 😀