+1 vote

what i want to do is, when all value in GlobalDta.skill_list["test_cd"][x].c_cd become 0 timer will stop, then i can check if all GlobalDta.skill_list["test_cd"][x].c_cd <=0 then i get true.

but after i get this result it stop decreasing.

one more thing,why when i make GlobalDta.skill_list["test_cd"][x].c_cd to var cd_list = GlobalDta.skill_list["test_cd"][x].c_cd then continue like this cd_list -=1 it wont work. it just decrease once then stop decreasing.

how should i make work? and why it happen?

func _on_Timer_timeout() -> void:
    for x in GlobalDta.skill_list["test_cd"].keys():
        if GlobalDta.skill_list["test_cd"][x].c_cd >0:
            GlobalDta.skill_list["test_cd"][x].c_cd -=1



json dict

  "test_cd": {
    "skill1": {
      "name": "fire",
      "c_cd": 1,
      "max_cd": 3.5
    "skill2": {
      "name": "water",
      "c_cd": 1,
      "max_cd": 10
    "skill3": {
      "name": "wind",
      "c_cd": 5,
      "max_cd": 5
    "skill4": {
      "name": "earth",
      "c_cd": 3,
      "max_cd": 6.5
in Engine by (390 points)
edited by

1 Answer

0 votes

You don't get the correct result because you're running your code on the timeout of the timer. Meaning that your timer has already stopped!

I don't know what you're trying to do exactly, but you should use a timer if you know in advance how much time you want to run something. In your car it seems to be the opposite?

I suggest you to move your code to _process(), that way you'll decrease every c_cd value by one, each frame. If this is too fast for you, you could setup a timer to do that every x seconds. But make sure to use a timer WITHOUT one_shot activated. That way, the timeout function will be triggered every x seconds indefinitely. You could then use stop if EVERY value is at 0.

by (619 points)
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.