[SOLVED] Multiple Instances of Object Onscreen VS Created Via Action

Hi, I ran a test in which I created three instances of an object on scene prior to loading. Then in game I created three more objects via an action using the event sheet. The issue is that these sets objects behave differently. Particularly when using a “for each instance of an object” command. I try to change the object variable on each later in the event sheet, but only the newly created objects seem to respond to the change. Though all six objects all still respond to clicks as they should, but with the variable offset. If I put the variable change before the creation of the new objects, the new objects of course don’t change…but the objects created on the scene prior to loading now do. What am I missing here?

Thank you in advance!

It’s hard to know what you’ve done or are doing without a screen snip of your events. So my response is a guess based on what could be the problem.

If you have the event to change the object variable as a subevent of the one where you create the new objects, then yes, that is the proper behaviour. When you create the new objects, they are the ones that are being referenced in the subevents, and not any of the existing objects.

Ahhh that’s what it was. It wasn’t technically a subevent, but when I moved the code to “change the variable” from the “play at beginning of scene” event to it’s own “trigger once” event it now works for each object instance. Odd that it didn’t work in there even though it was below in the action command line?

Thank you for the quick reply!

This event (and it’s sub events) will only fire once when the scene has loaded.


Again, unless we have a screen shot to go by, it’s a bit of a guessing game how you’ve implemented it.

This example doesn’t update the variable properly for the objects already on scene, but updates the created object above properly.

This example updates all variables proper, objects already on scene at start and the newly created one above.

A trigger once just says “Was this condition true last time? If not, then run this event”. So if you press a key and have a trigger once on the keypress, then it will fire once while the key is pressed. If you release the key and then press it again, it will again fire once (because the previous state was that the key was not pressed).

So, I’ll explain what you are doing here :

  1. You are creatign a new object and changing the object variable Count for just the Card1 object created. It does not change the exisitng Card1 objects.
  2. Every frame that the LMB is down, this event (and it’s subevents) are actioned. You really want a trigger once at this point. This will ensure it only get triggered once while the LMB is down. When LMB is not pressed this won’t fire, and it will only fire once every time LMB is pressed.
  3. This is not needed, because you are checking the cursor on Card1 further down.
  4. The trigger once is not needed here. The events will only be actioned once for the Card1 object because of the repeat block.
  5. This condition will create a list of Card1 objects that the mouse is over (for GDevelop to use internally). Any further references to Card1 in this event and subevents will be to just that list of Card1 objects. So the action only works on the Card1 that has the mouse over it.
  6. This event and action is only fro the Card1 objects from step 5.

I also think one of your problems is that the Card1 object you place in the editor do not have the Variable Count set to 1. I suspect it’s set to 0.

Anyway here’s an improved way of doing what you’re after. I’ve added comments to what each event does:

Very helpful thank you! Thanks for pointing out the “trigger once” location, I’d been wondering about that. I noticed it worked in both places, but didn’t know which was better. And you’re correct that my editor object variables were set at 0.