derkork / godot-statecharts

A state charts extension for Godot 4
MIT License
734 stars 35 forks source link

Adding actions to transitions #58

Closed SpicyFlanx closed 9 months ago

SpicyFlanx commented 9 months ago

The State Charts (format?) provides for actions being placed on transitions, and I think this might be a useful addition to the addon. For example, I'm working on a project with walljumping, which has different behavior from a regular jump. To model this, I've added additional "jump" states with associated entry actions so their execution can be handled by the state chart- but these states serve no other purpose, don't fit with my chart's conventions, and they aren't really states so much as actions that should happen alongside a transition.

Perhaps transitions should provide signals that emit when the transition occurs?

derkork commented 9 months ago

This is actually a great idea and should be relatively easy to add. I'll put it on the list.

derkork commented 9 months ago

Just to make sure we get a nice usable API: This is what I currently have in mind:

# on transition.gd

## Fired when this transition is taken. For delayed transitions, this signal
## will be fired when the transition is actually executed (e.g. when its delay
## has elapsed and the transition has not been arborted before). The signal will
## always be fired before the state is exited.
signal taken()

Will this be sufficient for your needs @Svaught598 , @SpicyFlanx ?

SpicyFlanx commented 9 months ago

@derkork It's working great, thanks!