danielpa Posted August 27, 2019 Share Posted August 27, 2019 (edited) I've seen some mods use the `Sleep` function, but when I try to use it in the modmain.lua file I get an error: modmain.lua: function main() AddPlayerPostInit( function() GLOBAL.TheInput:AddKeyDownHandler( string.byte("z", 1), function() print("BEFORE") Sleep(10) print("AFTER") end ) end ) end main() Error: [00:16:44]: [string "../mods/lib/modmain.lua"]:9: attempt to call global 'Sleep' (a nil value) LUA ERROR stack traceback: ../mods/lib/modmain.lua:9 in (field) fn (Lua) <7-11> scripts/events.lua:46 in (method) HandleEvent (Lua) <42-49> scripts/input.lua:187 in (method) OnRawKey (Lua) <184-191> scripts/input.lua:396 in () ? (Lua) <395-397> EDIT: using GLOBAL.Sleep: [00:02:53]: attempt to yield across metamethod/C-call boundary LUA ERROR stack traceback: =[C]:-1 in (field) yield (C) <-1--1> scripts/scheduler.lua:339 in (field) Sleep (Lua) <336-343> ../mods/lib/modmain.lua:6 in (field) fn (Lua) <4-8> scripts/events.lua:46 in (method) HandleEvent (Lua) <42-49> scripts/input.lua:187 in (method) OnRawKey (Lua) <184-191> scripts/input.lua:396 in () ? (Lua) <395-397> Edited August 27, 2019 by danielpa Link to comment Share on other sites More sharing options...
Ultroman Posted August 27, 2019 Share Posted August 27, 2019 Why do you need to use Sleep for anything? And how did the other mods use Sleep()? Link to comment Share on other sites More sharing options...
Serpens Posted August 27, 2019 Share Posted August 27, 2019 (edited) Just yesterday I solved the mystery of Sleep(). Take a look at game scripts that use it (not many), but for example within the talker component. You have to start the function that uses Sleep with a thread. Sleep does pauses the current function and waits x seconds. If you would call this without a thread, you would pause the whole game, cause everything is called in row. So to be able to call Sleep you have to start a parallel task that is independed of the game functions and there you can Sleep now. Edited August 27, 2019 by Serpens Link to comment Share on other sites More sharing options...
danielpa Posted August 27, 2019 Author Share Posted August 27, 2019 Yeah that solve it , thanks a lot @Serpens. How do I mark a (forum) thread as solved? Link to comment Share on other sites More sharing options...
Ultroman Posted August 27, 2019 Share Posted August 27, 2019 1 hour ago, danielpa said: How do I mark a (forum) thread as solved? Edit the original post and change the title and prefix it with [Solved] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now