I’m relatively new to GDEVELOP and am just trying to create my first game.
So far, I’ve overcome a lot of beginner problems I think, but for one I don’t find a solution.
I have read about the difference of “object” and “instance” variables and also know how to create them in the editor.
But I havent managed yet to create objects with individual (instance) variables in game.
I want to create various instances of objects during the game and use the command:
AMONG objects opponent_1, create object named “opponent_1” at position 1024, VARIABLE(CONST_YBASE)
This works and creates as many objects as desired in combination with a scene timer.
But when I try to create an individual variable for the object directly after the command above, using
CHANGE the variable speed of opponent_1: set to Variable(varRandom_value)
then the Variables of all created opponents are changed in this way (so I change the object variables).
But how could I create and modify an instance variable that differs from opponent to opponent?
I’ld be grateful to get any hint from you. Thank you in advance
thank you, yes, that would probably work for the speed that would be used only once.
But I have another property, where the once chosen random value for this (instance) of the opponent has to be used for another property that depends on the range (e.g. 1-7, 8-15…) so I decided to store the random value in a variable to be able to reuse it. The debugger shows me, once I set the variable, that it is set for ALL objects I created. Maybe I use the wrong command here? Thank you.
yes, I create the object with the commands above (after triggered by a timer event), but then all the variables of the already created objects are changed to the value. I’ve tried different variants, but still didn’t manage it.
Here’s the code snipped of an opponent called “note_1”:
Does anybody maybe have a code example, how to (1) create an object in game and afterwards (2) create an individual instance variable with an initial value for this object?
You’re right, that was a language mix . I translated one and forgot the other!
I tried your hint with the “create object” and this seems to be part of the solution, but not alone. Still all the instance variables had the same value. With some more tries, I came to the solution to separate the creation of the object and the setting of the variable in two events.
I also created the object variable “Noten_ID” in the Objects Editor and set it to -1.
In the 1st event, the object is created and it should have the initialized -1 value as Noten_ID
In the 2nd event mentioned, I checked the condition whether the variable is still -1 and then set the value I needed. looks a bit complicated for me, but works
Here is the now functional code for all who are interested (this time with no translation attempt at all )