juli wrote:Is it possible to make a function return a value after some seconds?
I mean if i write something like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local str = "some string"
minetest.after(3.5, function(str)
print(str)
end, str)
return str
Then the str is first returned and then printed, but is it possible to print it first and then return?
You're asking the wrong question, and so you're going to get the wrong answer.
Lua can't ever wait in minetest. If you would wait for 3.5 seconds in Lua, minetest would be frozen and nothing in the minetest world would change in that 3.5 seconds. And then after that 3.5 seconds, all of a sudden everything would "jump around" and be all weird.
What you should be asking is, "I have event A, and 3.5 seconds later I need to do something with that work in a certain way".
The problem is, I can't know what "something" is. And until you tell anyone, we're all left in the dark *guessing* what you're trying to do.
What you should try to do is learn about asynchronous execution and event-based programming. Minetest is a very event-driven API, and if you use it right, you don't need to wait (ever) and so your minetest server won't ever be halted. It's actually really hard to "halt" minetest for 3.5 seconds, for that very reason.
So, please take some time to elaborate and what it is that you want, instead of giving only a tiny bit of code that doesn't work.