Topic was automatically imported from the old Question2Answer platform.
Asked By
RobinGerst99
Old Version
Published before Godot 3 was released.
So I habe been making a flappybird like game and I was wondering how I can simulate mini lags. Basically, when I click a button I want to turn lags on or off.
Here you go, this script will make your game laggy if you press F4.
Attach this on any node, drop it anywhere in a scene.
extends Node
func _ready():
#set_process(true)
set_process_input(true)
func _input(event):
if event.type == InputEvent.KEY:
if event.pressed and event.scancode == KEY_F4:
set_process(not is_processing())
func _process(delta):
# Just run something insanely costy here
lag(500000)
func lag(iterations):
var n = 0
while n < iterations:
n += 1
You can make it react to a button if you make that button call set_process on this node.
Or simply if randi() % 20 == 0: OS.delay_usec(rand_range(0, 5000))
timoschwarzer | 2017-09-11 19:05
Aaaah right I was searching for sleep but couldn’t find it
Zylann | 2017-09-11 19:08
Yeah, there is OS.delay_usec() and OS.delay_msec()
timoschwarzer | 2017-09-11 19:19
Doesn’t have Godot a function to change the time step, delta? Decreasing it will make the game slower without having to make strange waits or charging the processor.
VictorSeven | 2017-09-12 18:33
I guess the point of simulating lag is to make it unexpected, uneven, so configuring Godot to actually reduce time step isn’t the same test. In fact, overcharging a CPU or making it sleep can also be a different test.