kubecz3k / FiniteStateMachine

FSM plugin for Godot
MIT License
116 stars 22 forks source link

Initiate transition when receiving signal #1

Open MrGreenTea opened 7 years ago

MrGreenTea commented 7 years ago

Hi, thanks for your awesome plugin. It works really well and makes developing way easier and more fun for me. I am using it a lot for my menus and similar things, so I want to initiate a state transition when a user clicks somewhere or an animation finishes. Currently, it looks like this:

var transit = false

func transitionCondition(inDeltaTime, inParam0=null, inParam1=null, inParam2=null, inParam3=null, inParam4=null):
    if transit:
        transit = false
        return true
    else:
        return false

func _onClick():
    transit = true

Is there an easier way for listening to received signals and directly translating them to a transition?

I hope I could make myself clear, if you have further questions please ask away.

MrGreenTea commented 7 years ago

Another way I found is

var transit = false

func prepare(inNewStateID): 
    transit = false

func transitionCondition(inDeltaTime, inParam0=null, inParam1=null, inParam2=null, inParam3=null, inParam4=null): 
    return transit

func _onClick():
    transit = true

This is a bit clearer and I like it better, but being able to connect the signal directly would be really great and feel very natural/godot-like

kubecz3k commented 7 years ago

I don't think there is more easy way at the moment. I'm doing this exactly like in your second paste. I will think about this a little more, maybe I will have any good ideas. For now the best Idea I have right now would be to add special transition subtypes like "onSignalTransition", and it would work exactly like the code you have pasted, but instead of 'onClick' you would have predefined 'onSignalOccour' and you would connect in editor to this function...

kubecz3k commented 7 years ago

But also for now I would want to stabilize this plugin a little before adding new features (think I will upload new update in Sunday, api has very slightly changed) Also will record this second video about it. If you will have any good ideas let me know!

MrGreenTea commented 7 years ago

Maybe in the editor, when creating a new transition, we could choose a signal from any node? Like as an additional option to "New Condition" and "Choose existing" there could be "On Signal" and then something like this view pops up and we can choose a node and signal? bildschirmfoto vom 2017-06-02 15 11 56

MrGreenTea commented 7 years ago

The only thing I noticed is that you are using camelCase for parameters, but godot uses snake_case for everything besides Classes and I love me some consistency :) But it's no biggie.

If I have further ideas etc. I will create issues for them.

kubecz3k commented 7 years ago

Unfortunately there is limitation for what Godot is able to do inside editor. if script or scene don't have 'tool' keyword at the beggining of the script it will be invisible for me inside the editor. That's why transition itself need to have it.

kubecz3k commented 7 years ago

@MrGreenTea sorry for camelCasing, I'm using it in all my projects and in fact I had blessing of reduzio. In old days he said the reason why gdscipt is not camelCase was because he thought people will use it and this way all custom script are instantly distinguishable :)

kubecz3k commented 7 years ago

I think I will open issue request some day for those tool signals, but don't want to flood issue tracker to much with that kind of stuff as there are already other more important feature requests regarding tools/pugins.

MrGreenTea commented 7 years ago

I see, it works well like it is currently. Maybe reduz has an idea how this can be accomplished. Somehow it must be possible, as the editor can do it and as far as I know the editor is also created with godot itself.

I didn't know that about camelCase. As a python user I am glad that nearly everything is snake_case.

kubecz3k commented 7 years ago

In any case I think I could make user part snake_case since in the end those are only couple short script templates, but I haven't thought about this early enough. Not sure if it's worth now to make such big change (at least from user perspective) (also this plugin is on the asset store for many months now, only transition part was recently added, the rest is quite unchanged - not sure how many projects are using it)

MrGreenTea commented 7 years ago

You can see the total count of clones in your traffic graph under Insights. If you don't feel comfortable with it now, you can always leave such a change for big backwards-compatiblity breaking release.

MrGreenTea commented 7 years ago

I'll leave this ticket open for further discussion on the idea of having signals directly initiate a transition and for you to keep track of it.

kubecz3k commented 7 years ago

I meant people who simply downloaded this plugin from asset store

MrGreenTea commented 7 years ago

I assume that they just do a clone too, but I might be wrong.

kubecz3k commented 7 years ago

hah I doubt it, I'm downloading it from asset store myself when I'm doing some new projects

kubecz3k commented 7 years ago

Maybe not exactly the same but in recent commit there is accomplish() buildin method for transitions. It works exactly the same way how your second sample code.

ageofabenius commented 6 years ago

Another alternative would be to use manual update mode and use signals to trigger the updates.