Search code examples
godotgdscript

how to execute a function inside the process function of godot every 1min?


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

I would do this 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 call or execute a function deduct_one_coin_every_one_minute(uid)


Solution

  • This would probably best be solved with a Timer node. You can add it to your scene either in the scene editor or in your code, and connect the timeout signal to your deduct_one_coin_every_one_minute() function. Then, set the wait_time to 60 and call start().