I have a global timer autoload in my game that I use to keep track of time. The timer starts right when the player hits the "Start Game" button. I need my animation player ( which is playing my Day Night Cycle) to play the cycle right when the Clock is no longer zero seconds ( NOT when the player hits the button)

I can see my global timers time increasing in the output screen so it works. My day / night cycle also works WHEN I don't have it attached to the global timer ( when I simply just play it in the ready function of my main script).

Below is my code:

/////////////////// My Main Scripts Code ////////////////////////////////////////

extends Control



func _ready():
	
	if WorldClock.ExactWorldClockTime >= 1:
		$AnimationPlayer.play("DayNight")
		print("DayNightCycle Begins Now!")

I wanted my "If" statement to start it but it won't, it doesn't even print the statement " Daynight cycle begins now"

///////////////////// My Timer ////////////////////////////////////////////////

extends Node

onready var WorldTimer
onready var ExactWorldClockTime = 0


func _ready():
	WorldTimer = Timer.new()
	WorldTimer.set_one_shot(false)
	WorldTimer.set_timer_process_mode(Timer.TIMER_PROCESS_IDLE)
	WorldTimer.set_wait_time(1)
	WorldTimer.connect("timeout", self, "_on_Clock_timeout")
	add_child(WorldTimer)

func _WorldTimerStart():
	WorldTimer.start()

func _on_Clock_timeout():
	ExactWorldClockTime += 1
	print_debug(ExactWorldClockTime)
	pass

Please Help! Thank You! :)

_ready() only executes once and when the node enters the scene tree.

You are waiting one second. The_ ready call for your Control will execute well before one second expires

And you can also get milliseconds from game start directly:

https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-get-ticks-msec

You can have your control play day or nite cycle by binding it to the WorldTimer's signals and do the test your are doing in _ready in the timeout call (you will have to break the connection after or the animation will trigger every second there after).

you can also use yield:

https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html#coroutines-signals

@dotted Thank you for your advice! I tried using yield and it refused to resume when I clicked the button that I wanted to resume my day night cycle. The game would yield though, just wouldn't resume.

My worldTimer is in an autoload and has no actual node. How would I get my day night cycle which is a child of a node to pick up a signal from it?

EDIT: I got the yield you mentioned to work! I just had some bad misspellings, thank you!!!

I found another way to fix this, I used the function:

func _process(delta)

I set up my "if" statement test inside of it and it worked! At first I thought this function was only for player movement updates but it seems to work for autoload functions as well! =)

process is called once per frame, generally player movement should happen in physics_process() if you are using any element of the physics engine.

The difference here is _process() is called once per frame rendered varies with frame rate to my understanding, while the physics variant is 60hz (by default).

I am a little curious though, your animation is a day night cycle but:

if WorldClock.ExactWorldClockTime >= 1:
        $AnimationPlayer.play("DayNight")
        print("DayNightCycle Begins Now!")

This is being started once a second (?), does this make sense?

@dotted said: I am a little curious though, your animation is a day night cycle but:

if WorldClock.ExactWorldClockTime >= 1:
        $AnimationPlayer.play("DayNight")
        print("DayNightCycle Begins Now!")

This is being started once a second (?), does this make sense?

In theory, because of how the "if" statement is set up, you would think that the animaton would just keep resetting from the beginning every one second but for some reason its not, it plays like normal. I honestly have no idea why this works but I'm gonna stick with it lol.

@dotted said: I am a little curious though, your animation is a day night cycle but:

if WorldClock.ExactWorldClockTime >= 1:
        $AnimationPlayer.play("DayNight")
        print("DayNightCycle Begins Now!")

This is being started once a second (?), does this make sense?

Because it's in _ready()

@Megalomaniak Yes but she moved it to processs

Oh, then that is a bit curious indeed. Maybe something about the animation track itself? What property/value is it actually animating/driving and by how much?

2 years later