PilzAdam wrote:You can use milliseconds in minetest.after(). In the function you can set a boolean variable to false and check it in the main code.
Nope, not working. Neither with globalstep:
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 global_timestep = false
minetest.register_chatcommand("infinite_loop", {
params = "",
description = "Wait for a global variable",
func = function(name, param)
global_timestep = false
local counter = 0
repeat
counter = counter + 1
print("Waiting for external bool..."..counter)
until global_timestep or counter == 1000
end,
})
minetest.register_globalstep(function(dtime)
if not global_timestep then
global_timestep=true
print("Set boolean true")
end
end)
Nor with after:
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 global_timestep = false
minetest.register_chatcommand("infinite_loop", {
params = "",
description = "Wait for a global variable",
func = function(name, param)
global_timestep = false
local set_true = function()
global_timestep = true
print("Set boolean true")
end
minetest.after(0.01, set_true)
local counter = 0
repeat
counter = counter + 1
print("Waiting for external bool..."..counter)
until global_timestep or counter == 1000
end,
})
Once in a loop, no chance that any timer gets a turn. I added an additional counter, that when somebody wants to try this code doesn't has to kill the minetest-process.
PilzAdam wrote:Another method would be to split up the main code into small functions and execute them in minetest.register_globalstep()
Wow, make an iteration, save
every value so the next iteration is able to load every value and proceed where exited before. That's a tough job just because there is no precise time-function.
Sorry, same issue here. No solution.
Is my wish so absurd? Am I the only one caring about mods getting so complex, that you have to warn the users to either buy high performance machines or better have no mobs/ambient sound/whatever?