Skip to content

Conversation

@4ian
Copy link
Owner

@4ian 4ian commented May 20, 2019

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).

@blurymind
Copy link
Contributor

this would be amazing for creating state machines

@4ian
Copy link
Owner Author

4ian commented Jul 16, 2019

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

@blurymind
Copy link
Contributor

blurymind commented Jul 16, 2019

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

@4ian
Copy link
Owner Author

4ian commented Jul 17, 2019

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.

@blurymind
Copy link
Contributor

I see, thank you for clarifying :)

@4ian 4ian marked this pull request as draft June 1, 2020 08:07
@4ian 4ian force-pushed the master branch 3 times, most recently from 8a32fc5 to 846afd9 Compare August 30, 2025 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants