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.

in Engine by (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():

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

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.

by (27,537 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.
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.