Original instance of an object works as intended, but other instances do not

Hello, i have a problem.
I made an object that should kinda work like a container; what i mean is, if you drop an object representing a log of wood in my game, it should:
a) add 1 to object variable informing on how much wooden logs is stored in there
b) destroy the log that has been “put” in the container
and after clicking on it, it should:
a1) spawn a log
b1) subtract one from the object variable that is counting logs
c1) repeat the process listed in a1 and b1 “stored logs variable” times

and on original instance of an object it works as intended, but when i try to use another instance of this object to store logs it reacts in two diffrient ways:
a) if og container is empty, you can throw logs onto the instance, and it will count them, but you can not take them back from the container
b) if og container has at least one log, when trying to take logs out of the instance of container, it will spawn stream of logs, that is not ending. also it does not subtract any instance value to my knowlage ( i checked that using debugger)

here are the screenshots, pls help:

Here’s another way of doing it. Most of the time, you want the conditions outside of things like repeat and for each events. As is, Gdevelop doesn’t know which newsprite10 to use as the count for repeat so I believe it uses the count of the first created instance.

Since the conditions inside the repeat don’t change then it’s more efficient to just check them once outside of the loop. I added pick nearest basket in case 2 baskets can be clicked or touched at a time. This isn’t needed if it’s not possible. I also changed the plus 1 to the number of objects picked (meaning the number of logs in collision with the basket) I used a counter variable instead of wood and I used that variable to spread out the wood.

Use as much or as little as you want.


thanks, i will later let you know if it worked :heart:

1 Like