Hi guys,
Noob question here…
So I noticed that Gdevelop gives you the possibility to create variables for EACH instance in your game.
How can I call this variable in the events sheet? Gdevelop shows and allows you to select Object variables, but what about Instance Variables?
Hi
“En voilà une question qu’elle est bonne !” as we say in France.
A+
1 Like
Not via expression but via condition
Look you make variable Called ID
And now you have 2 objects which are same object but just copy of it
And you give one in ID variable value of 2 in other you give it 5
So now you can make event
Condition
Object variable ID = 5
Action
DO something
Even so you have multiple instances of same object
You just targeted only one instance
And now something that blow my mind when i 1st realized it
Read my message again but replace in your mind ID with HP
1 Like
Not sure if this can help my case.
Your explanation is cool, I do use something similar to target different instances of the same object.
I think this is my fault
Let me give you another example.
Say I have this object named Polo.
As of now Polo has no variables declared in his variables table.
Gdevelop gives me the option to add a variable from the instance tab.
I want to know how I can use this variable, without needing to declare it in the object variable tab.
Thinking about it, this is probably a visual bug. cause if you click to open the instance variable tab from here…
There is no option to add a new variable unless you put it from the object variable tab!!!
So I guess the + symbol just exist for no reason?
Funny thing is that if you click + it creates variables that you can see but can’t use?
Maybe this function was here before Gdevelop’s variable update where you didn’t have to declare your variables. I don’t know
You are confusing what is what here but on other hand UI is not intuitive enough that you should get it on your own
TECHNICALLY you can use them
BUT because you did not declare your variable it will NOT link itself when you type it in condition/action
So you add instance var called Variable2 now you can make condition
Object variable Variable2 = 3
Variable2 will be red cause it is not declared BUT it will totally work
NOW to understand what is going on there
First of all proper names
When you double click object and go to variable tab
THAT are OBJECT variables
Instance panel from your screenshot is INSTANCE variables
Instance variables are variations variables of that object variables
FOR EXAMPLE
You make object called Zombie
You give Zombie HP OBJECT variable and set it to 100
NOW you copy/paste 20 Zombies on your scene
Let’s say player is on the left and zombies on right
You want zombies to move in formation to the left so toward player
BUT you don’t want them all be the same durability
You made 5 rows of 4 columns of zombies
You want 1st 2 columns (1st two front lines) be weaker targets
So what you do?
You check in game if their position is less than X something and greater than X something?
NO you select these objects in your editor
In instance variables panel you change their HP var to 40
And now they will be weaker
WHERE if you drag from object list Zombie object and place it on scene THIS one will have 100 HP variable cause that is what you set in object window
Same as Zombie objects that you did not change instance variable HP to 40 will still have 100
So instance variables are like
Make object variable have different value FOR THIS OBJECT I SELECTED from what is default value of this object for this variable
Now other part of story some time ago we did not not need to declare variables at all
And it was tragic ppl were adding to Score where they would check score
And gdevelop is case sensitive
So consider this change an upgrade
And you could write ANYTHING in action/condition for variable and there was NO way to determine if that variable is used elsewhere or did you type it correctly (again Score score) and are you going for global or scene correctly?
So i assume they simply did not remove option to set instance vars until object var is set
Cause again
Instance variable is object variable just with different value than default
I believe that’s a bug that’s been around for awhile. You can use the object edit screen to modify an existing object variable which I guess also creates an instance variable but if you create the variable through it, it doesn’t appear in the autocomplete. From my experience, you need to create the object variable first and then modify the value.
All instances of an object need to have the same variables anyway for consistency and the autocomplete. If an instance didn’t have the variable defined GD wouldn’t know what type of variable to expect and would probably return zero.
1 Like
Wonder if they will ever fix it.
It’s not an engine-breaking bug, but it can cause confusion, hence the confusion of this post. They just need to remove the + symbol.
1 Like
Hi everyone
Or to put it in gray and therefore ineffective.
Xierra
1 Like