#How can i stop a coin/anything like a coin. To stop spawning after a certain number
39 messages · Page 1 of 1 (latest)
Where do you spawn it in code ?
Made a coins script for it
Could you send it here ?
Oh it's because the timer is set to loop
You can click the timer in the scene tree and tick the "One Shot" box
Yeah but I want the coin to spawn again but stop spawning after a certain number
Yeah if I understand correctly you want to spawn 3 of them right ?
Wait so you do want them to keep spawning ?
yes but not like after 3 they spawn more
Oh I see
Okay so let me check if I understand correctly
You want to spawn 3 coins when the game starts
And then whenever you pick one, a new one spawns ?
yes
Okay, and what is the timer for ?
for them to spawn after a certain time
Alright, and you want them to also wait some time before respawning ?
yeah
Okay
So what I'd do :
You still set the timer to One Shot, so it only spawns 3 coins when the game starts
And in the function in which you pick up the coin, you can do :
await get_tree().create_timer(wait_time).timeout
#spawn the new coin
okay maybe i'm doing it wrong but after spawning for the first time then getting them they don't spawn again
Can you show me the function in which you pick up the coins ?
Okay, so in your coin_get() function, you can add this
So whenever you get a coin, it waits X seconds then spawns a new one
like this ?
That wouldn't work because the coin will be destroyed before it can spawn the new one
I would entrust this to the GameManager.coin_get() function
But now that I think about it I think you need to do get_tree().create_timer(wait_time).timeout.connect(my_spawn_coin_function)
So it won't halt the destruction of the first coin
This line basically says "keep moving through the function, but when the timer I just created runs out, call my_spawn_coin_function"