I have asked a similar question before but I don’t understand the answers I get, since they aren’t that detailed. I have also read other users question on the topic, still not understanding. Further I have looked around on Youtube, trying to find the right tutorial. My question is how to adress specific instances of an object. I would really appreciate a step by step guide that shows how to create instance variables, instance IDs, object filtering or whatever is needed and then call each of those instances and make unique changes to that particular instance. Is there a tutorial out there that can guide me? Or even better an example project?
In my case I have five instances of an object (an image) that should change color (animation number) when the player gets more points. If the player gets one point the first instance should turn green and if the player gets two points the first and the second instance should turn green and so on.
Unfortunately, there isn’t something that is going to address all of those questions, nor a step by step guide for it, because how you pick instances is very unique to each game.
However, to understand the basic of object selection: Object Picking - Intermediate Tutorial - GDevelop - YouTube
Object/Instance variables: Variables - Intro Tutorial - GDevelop - YouTube
If you cannot select your object via the methods mentioned in the object selection video, then you will need to develop instance variables for each instance in the scene. This means either predefining the variables on each instance themselves (create a variable on each instance named “id” and give each a unique variable) or you will need to create some sort of instance tracking variable that you increase each time you create a new instance via events, and then apply that variable as the ID for the newly created instance.
Beyond that it will be up to you how and when you use that ID variable to pick a specific instance, but it will almost always have to be in combination with other conditions to narrow the object selection. Once you have the ID variables created (precreate or via events), you can always call it later with ObjectName.Variable(yourIDvariablehere).
Since you’re precreating your objects, I would just give each one an ID variable with the values of 1 through 5. Then you would just set up an event that says “Value of ID variable of Objectnamehere =< Variable(YourPointsVariablehere)” as the condition, and your actions would be whatever you want to do to that object.
A big thanks for your reply Silver-Streak. Now I have come a bit closer.
It still seems a bit weird that (in the video) you first have to uncheck all instances of the object and then check the name of the object itself, and by doing that Gdevelop “automatically” knows which one of the instances needs to be checked based on a previous collision. As if the collision itself doesn’t recognise the instance unless you first “reset” all instances.
With my lack of understanding how GDevelop works under the hood I find it a bit far fetched, almost like an other advice I read about where one also can check the z-order of the instance to find the right instance. This would require that I always know what z-order an instance has and that it never will change during the process of creating the game or by dynamically creating new instances that might change the z-order within the game.
So if I have understood things right there is no straight forward and persistent way to identifying instances? You can only narrow it down by checking the circumstances surrounding that particular instance at a certain time. Such as a collision or a z-order.
Both of these methods seem a bit vague (or unclear) to me, so I think that the ID variable method seems to be the most predictable way to go. I have tried this method earlier but for some reason GDevelop chose the wrong instance every time i tried to call it. Probably I made something wrong. Anyways, I’ll give it another try, Once again, thanks for leading me in the right direction.