Modifying specific instance variables from event section

Hello all. As the title says I want to change an object’s instance value from event section. But when I try to change it, all the other instances’ value changes too. I searched forum yet didn’t find my answer so decided to write a topic about it. I need your help, please help me understand gdevelop better :slight_smile: And down below of course my example and what I wanna do. I read about picking nearest object function and repeat for each instances but still couldn’t figure out how to use it properly. :confused:

In my example I need to increase (let’s say) ground object’s value by 1 just by pressing any key. There are 6 instances and 1 Player. But when I press any key I want only closest one to increase its value. How do I achieve this? My code:

Condition order matters in this case. I think it is basically choosing the nearest ground with 0…then the next one, etc.

Move the “pick neatest” to the top of the condition list of the event it is in.

Also, add Trigger once as a condition to the bottom of that event as well.

1 Like

Thanks a lot for replying this fast :smiley: I did as you mentioned but nothing changed, result is the same for some reason. Is it possible to achieve this by using pick nearest object?

My result: (tweaked the example a bit to make it less complex)

Your text objects are also only tracking one (likely the first) ground object. They have no way to know which ground object you mean, so they’re just showing the first one that matches.

You should launch the debugger and check that the other ground object variables aren’t actually getting updated.

If they are getting updated in the debugger, you will need to update your text objects to be linked to your ground objects upon creation, and have your separate “Update text” events also use the “Take into account linked objects” condition.

You can see an example of this in the “basic pathfinding with AI” example, although it’s using sprites (named Alert) instead of text.

1 Like

Yes it is as you mentioned silver. Thanks to your information I used debugger and realized each instance has different value meaning they are getting updated yet there is no text change. Still we achieved this feat, that’s cool. But couldn’t figure how to update text value, still need your help. I will show my update on code: