|
|
|
|
Reply From: |
jgodfrey |
Based on the above code, the problem would seem to be that all instances of your seed packets are looking at the same, global seed count value. And, when that value reaches 0, each instance automatically deletes itself.
To fix that, you’ll want each independent instances to track its own seed count. So, rather than having a single, global variable - each seed packet object should have its own script that tracks its own number of remaining seed. With that, the instance will delete only itself when its seed count reaches 0, but the others will remain.
I really appreciate this! I am using signals now to connect, so this could be the root of my problem, but it still has yet to work. I’m not sure how clear I was with my wording, because it isn’t every type of seed packet that it deleting, but ones of the same type. The others remain just fine but the ones of the same type, say corn, would delete both packets even though I’m only using one. If you have anything that could be helpful that would be great!
raeeeeeeeeee | 2022-12-16 22:21
So, looking at the code you posted above, here’s what I think is happening:
You have multiple “Corn” seed packets, each with this script:
func _process(delta):
if Global.cornseeds == 0:
queue_free()
So, in every frame, every single “corn seed” packet looks at the single, global value Global.cornseeds
and when its value reaches 0, the object deletes itself. So, as soon as that variable reaches 0
, every packet that’s monitoring that variable will delete itself.
You can’t have MULTIPLE instances of same object all monitor the SAME value and expect them to behave independently.
Again, to solve this, you’ll need to track the count in each packet independently. That could be done in the the local script associated with each packet, or in a global script, where each packet has its own unique counter to reference and update (likely in a dictionary).
It’s hard to make any more specific suggestions without seeing all the related code.
If the project is available somewhere for inspection, I’d be happy to take a look and (potentially) offer additional input.
jgodfrey | 2022-12-16 22:45