Advertisement
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 = 30 -- You can play a bit with these values
- loop.iteration_cooldown = 4000 -- This is the best one when you need to spam a bunch of tasks that are not that heavy!
- loop.accept_faster = true -- It runs it all as fast as it cans
- -- These tasks are very soft so this configuration will be one of the bests for it!
- -- You can spam the spacebar, as an example of task spamming
- function keyboardTask(player, key, down, x, y)
- print("Key pressed, executing some code!! Current task runtime is " .. loop.current_task.real_runtime() .. "ms")
- loop.sleep(30) -- We use loop.sleep
- print("Half of the code has been executed. Executing the other half! Runtime is " .. loop.current_task.runtime .. "ms")
- loop.sleep()
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement