0 votes

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)

Godot version 3.2.3
in Engine by (29 points)
edited by

1 Answer

+2 votes
Best answer

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.
by (11,901 points)
selected by

Could you guide with code rather with editor?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.