GDevelop icon indicating copy to clipboard operation
GDevelop copied to clipboard

Add support for passing a behavior as parameter in an expression

Open 4ian opened this issue 6 years ago • 5 comments

Checking what's the best way to support passing behaviors as parameters in expressions:

  • either pass their names, implying the usage of the previous object: (MyObject.DoSomething("MyBehavior"))
  • or pass a fully qualified "reference" to them: MyObject.DoSomething(MyObject.MyBehavior).

4ian avatar May 20 '19 22:05 4ian

this would be amazing for creating state machines

blurymind avatar Jul 16 '19 18:07 blurymind

What do you have in mind exactly? :) But yeah that would unlock some pretty advanced things by composing behaviors.

4ian avatar Jul 16 '19 18:07 4ian

well for example if you have MyObject.DoSomething("MyBehavior") and MyBehavior is stored in a string that can be changed :) no longer a need to manually create lots of if "specific string" > do stuff for that state. You can simply call the behavior directly by changing the string -this makes for a nice shortcut when creating a state machine.

MyObject.DoSomething(currentState)

see how he is storing each state in a different script https://www.youtube.com/watch?v=EvYXRefDQHU&list=PL9FzW-m48fn2ug_FSNnfozQs3qYlBNyTd&index=8

anyway, just idea, not sure how it would work with gd yet :p

blurymind avatar Jul 16 '19 18:07 blurymind

Ok, this feature is more about passing behaviors as parameters of functions - which is supported for action/conditions but won't work currently for expressions. Don't be fooled by the usage of a string (which might not be the case at the end), GDevelop still need to know what behavior you're asking for in the list of the function parameters, otherwise it can't compile events from your functions to JavaScript. In the future, it might be possible to have behavior "interfaces": i.e: you can call a function (as a action/condition/expression) passing a behavior that is not necessarily the exact one asked by the function, but one that has a similar interface (i.e: the same action/conditions). But this is out of scope for now, here again the idea is just to allow functions being expressions using behavior as parameters to work.

4ian avatar Jul 17 '19 09:07 4ian

I see, thank you for clarifying :)

blurymind avatar Jul 21 '19 20:07 blurymind