0 votes

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.

asked Sep 10, 2017 in Engine by RobinGerst99 (20 points)

1 Answer

0 votes

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.

answered Sep 11, 2017 by Zylann (27,009 points)

Or simply if randi() % 20 == 0: OS.delay_usec(rand_range(0, 5000))

Aaaah right I was searching for sleep but couldn't find it :O

Yeah, there is OS.delay_usec() and OS.delay_msec()

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.

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.

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.