call function while game process is running every 1 min

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By soeng kanel

I need to implement to deduction coin for every 1 minute from user.

I would do this in my Player.gd

var game_started = false
var time_start = 0
var time_now = 0
func _process(delta):
   if game_started == true:
   //deduct_one_coin_every_one_minute(uid)

func start(pos):
	print("clicked start the game");
	time_start = OS.get_unix_time()
	set_process(true)
    game_started = true

How to can I call or execute a function deduct_one_coin_every_one_minute(uid)

:bust_in_silhouette: Reply From: Calinou

You can use a Timer node to achieve that.

  1. Create a Timer node in the scene tree dock.
  2. Configure the Timer to have a Wait Time of 60 seconds, disable Autostart and Oneshot. When the game starts, call the start() method on the Timer node: $Timer.start() (if your Timer node is a child of the node the script is attached to)
  3. Connect its timeout signal to a new method in your script.
  4. In the new method, deduct 1 coin from the player’s coin count.

Could you guide with code rather with editor?

soeng kanel | 2020-12-30 13:04