#How can i stop a coin/anything like a coin. To stop spawning after a certain number

39 messages · Page 1 of 1 (latest)

quiet sage
#

Hi so I've been making a game just to kinda learn godot and gdscript but i ran into a problem, my coin keeps spawning every 5 seconds I wanted to know how can i stop it from spawning. Thanks

#

Oh forgot to mention i mean like they spawn i get them and they spawn again

remote flame
quiet sage
#

Made a coins script for it

remote flame
#

Could you send it here ?

quiet sage
#

Sure give me a few minutes

#

Had to use my phone sorry

remote flame
#

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

quiet sage
#

Yeah but I want the coin to spawn again but stop spawning after a certain number

remote flame
quiet sage
#

yeah and the get them then spawn again

#

then*

remote flame
#

Wait so you do want them to keep spawning ?

quiet sage
#

yes but not like after 3 they spawn more

remote flame
#

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 ?

quiet sage
#

yes

remote flame
#

Okay, and what is the timer for ?

quiet sage
#

for them to spawn after a certain time

remote flame
#

Alright, and you want them to also wait some time before respawning ?

quiet sage
#

yeah

remote flame
#

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
quiet sage
#

okay maybe i'm doing it wrong but after spawning for the first time then getting them they don't spawn again

remote flame
quiet sage
remote flame
#

So whenever you get a coin, it waits X seconds then spawns a new one

quiet sage
#

like this ?

remote flame
#

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

remote flame