I’m currently creating a new function in my game’s extension to simplify repeated action calls. In one of the actions, there is a part for changing a global variable. I’m using the action “Change variable value” for this. However, the problem is that the parameter cannot recognize the global variable I’ve defined in my game.
On the other hand, when I change an array using the extension “Array tools” > “Global variable/Array access” > “Shift array child,” it can read the global variables in my game. Why doesn’t the default action in GDevelop work this way?
Note: English is not my native language, so sorry for any mistakes.
They keep modifing the variable system. They don’t really want people using scene or global variables within extensions. Extensions are meant to be self-contained. Isolated. Easily reusable.
They would prefer that you either create a function that’s an expression. You could then set the return value to your global variable. Or you could supply the global variable as a parameter of the type variable.
You could then copy the variable parameter to an extension variable, modify the extension variable and then copy the extension variable back to the variable parameter.
https://forum.gdevelop.io/t/not-a-bug-variable-parameter/65018/2?u=keith_1357
It adds extra steps but functions are meant to be self contained. By suppling the variable or creating an expression, the function is able to be used with any variable or with multiple variables.
Well, if they want the extension is isolated, then they should create a separate feature for creating functions to help users with repeated actions.
As for your suggestion, it’s great for copying variables, but the problem is my global variable type is structure like soldier[building.id].team
—lmao
Can you provide more info? Where is the ID coming from? If it’s coming from an object then you could pass the object as an additional parameter. Then if needed, you could then use a for each object inside the function.
Depending on your need, an alternative might be for each child to cycle through an array or structure.
There are so many different ways to do things. Functions can be actions, conditions or expressions. You can also create behaviors which are more automatic or even a custom (prefab) object. Although, I’m not sure how efficient prefab objects are when used on a larger scale. I believe in minimalism.
You could use for each child or for each object either within the main event sheet to repeatedly use a function. Or 1 function can repeatedly call another function.