-
Required behaviors can't be passed through function parametersI did a quick and dirty try for this change request: https://trello.com/c/U8hR6L7l/392-allow-behaviors-to-be-configured-to-work-with-other-behaviors-behavior-composition
But I guess it's not expected to have parameters on the lifecycle functions so the caller doesn't pass Behavior2 and it crashes at preview. Passing required behavior through something like properties?In the following generated code, this indirection
It may happen that 2 required behaviors also required each the same behavior. So, the name have to be used to distinguish them or explicitly use the same one. Behavior A required behavior names:
Behavior B required behavior names:
Behavior D required behavior names:
Forbid to change the behavior name at runtime?If they are changed at runtime it would switch between 2 behaviors with theire own state (it won't just be a just switch between 2 configurations) which is not very intuitive even if it can be useful. Separate required behaviors from properties?The required behavior types will be defined in the behavior editor and the corresponding behavior name will be defined in the object editor. This looks a lot like properties. Using another list could give some structure but it may not be a good idea to add a new concept where properties seems to fit. Solution with required behaviors as propertyAllow to use required behaviors in the behavior functions events sheetThe required behaviors can be add to the object by passing an optional What should be set in the behavior parameter functions that are called in the events? The parameter name? Required behavior property declaration must have a behavior type attributeRequired behavior property affectation must autocomplet with the behavior names on the owner objectThis is similar to what the behavior parameter field does. Generate call to property getter for required behaviorsProperties may allow to switch behaviors at runtime, but required behavior can be added to the same map as for parameters if this must be avoided. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
The GUI part is implemented, I still have the code generation part to do but I have a general idea of how to do it. |
Beta Was this translation helpful? Give feedback.
-
Just making a separate answer to say that this might be a bit complex, but this can unlock a new generation of behaviors that are based on existing behaviors to extend them (like an improved platformer behavior, some AI based on top down movement, etc...). Very exciting!! :) |
Beta Was this translation helpful? Give feedback.
-
The code generation seems to work. I made a perpetual jump extension to try it. The only change is at the end. "PlatformCharacterBehavior" is set from a property. Name conflicts could happen between required behavior passed as properties or function parameter. gdjs.evtsExt__NewExtension__MyBehavior.MyBehavior.prototype.doStepPreEvents = function(parentEventsFunctionContext) {
this._onceTriggers.startNewFrame();
var that = this;
var runtimeScene = this._runtimeScene;
var thisObjectList = [this.owner];
var Object = Hashtable.newFrom({Object: thisObjectList});
var Behavior = this.name;
var eventsFunctionContext = {
_objectsMap: {
"Object": Object
},
_objectArraysMap: {
"Object": thisObjectList
},
_behaviorNamesMap: {
"Behavior": Behavior
, "PlatformCharacterBehavior": this._getPlatformCharacterBehavior()
}, I think that it would be more logical to have an expression (not editable) like
|
Beta Was this translation helpful? Give feedback.
-
I opened a PR draft: #2781 |
Beta Was this translation helpful? Give feedback.
I opened a PR draft: #2781
I had an issue with property extra information. I quote the code on the PR.