Simple Delay?

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

Is it possible to somehow get a variable to get timed for a certain time like 5 seconds and make it go from True to False?

I keep trying to figure something out but i somehow cant get anything to work.

var Timing = true

to

var Timing = false

After like 5 seconds the variable goes from True to False.
Any help with this would be great thanks.

Mahadev Dp

Love Status

God Wallpaper

lakki365 | 2023-03-11 16:14

:bust_in_silhouette: Reply From: kurtsev0103

Depending on your need - there are several options

  • Do this inside the code with yield
yield(get_tree().create_timer(5.0), "timeout")
timing = false
  • Do it in another method asynchronously with connect to the timer
get_tree().create_timer(5.0).connect("timeout", self, "set_timing", [false])
func set_timing(value: bool):
   timing = value

Bit late but would like to ask is there some thing that needs to be done first for the first line of code to work? I am not so familiar with yields cant get it to work i might be missing something.

  • Thanks

HaptikRevamp | 2021-10-11 10:15

You don’t need to do anything extra. yield stops code execution and waits for what is inside the yield to complete.

So if there is a fragment of code which should be executed immediately it is better to place it above yield or use the second option with connect (written above).

kurtsev0103 | 2021-10-11 11:57

1 Like