Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do
- local _, nickname = pcall(nil)
- tfm.get.room.owner = string.match(nickname, "(.-)%.")
- end
- local await = coroutine.yield
- local loop = Loop()
- loop.max_runtime = 20 -- You can play a bit with these values
- loop.iteration_cooldown = 5000 -- This specific configuration will run almost anything
- loop.accept_faster = false -- It is the best one when you need to spam a bunch of heavy tasks!
- function useTooMuchRuntime(howMany)
- local start = os.time()
- while os.time() - start < howMany do end
- end
- -- You can spam the spacebar. It will run anyways. If you spam it, it will be a bit slower and it will
- -- not print anything for some time, but it will run!
- function keyboardTask(player, key, down, x, y)
- print("Key pressed, executing some code!! Current task runtime is " .. loop.current_task.real_runtime() .. "ms")
- await(Task(useTooMuchRuntime, 30)) -- We create the task and we yield it so
- print("Half of the code has been executed. Executing the other half! Runtime is " .. loop.current_task.runtime .. "ms")
- await(Task(useTooMuchRuntime, 30))
- print("Alright, ended running the code! The total runtime is " .. loop.current_task.real_runtime() .. "ms")
- end
- function eventKeyboard(...)
- local start = os.time()
- loop.add_task(Task(keyboardTask, ...))
- loop.run_tasks(start) -- We can call this function from any event, and it is better
- -- because it will run faster when it cans!
- end
- function eventLoop()
- loop.run_tasks() -- We don't call it as eventLoop = loop.run_tasks because the eventLoop has arguments, and it will just break the system
- end
- system.bindKeyboard(tfm.get.room.owner, 32, true, true)
Add Comment
Please, Sign In to add comment