if something == true then
minetest.register_globalstep(function(dtime)
--Do stuff
end)
end
This is in the highest local space of a file called by dofile. It doesn't work though, the global step does not register. If you need more info just ask. This is probably simple so please forgive my naive question.
Are you sure your file is parsed (first step) and sure that something is really true? Then are you sure --Do stuff actually does something?
An ugly debugging way to check could be to add some minetest.log('error', 'Hello') at some points to see if your code is really executed (warning: this will probably fill up your console, be ready to quit game quickly). You can also put if something == true then minetest.log('error', 'something') else minetest.log('error', 'not something') end.
Don't do this at home, this is too ulgly. Don't forget to remove all those logs just after. You can use print instead if you run minetest from terminal or check debug.txt. This would be a little cleaner. Then you can look for all print before releasing because there is no point to put a print in file.
It would be a little more easy to debug with the actual code.
If you do so it is checked at least every time the function could be effectively run.
If you check before registering you check it only once for all. This prevent reenabling it automatically once the server is run (by changing a variable in-game, but you can reenable it an other way), but is cleaner. So you doesn't register an useless globalstep.
It's a question about code styling and "beauty", because a function call and a check every 0.1 or 0.05s (or even 0.01) won't make any difference, but hey, why would you do useless things?
if something == true then
minetest.register_globalstep(function(dtime)
--Do stuff
end)
end
This is in the highest local space of a file called by dofile. It doesn't work though, the global step does not register. If you need more info just ask. This is probably simple so please forgive my naive question.
Thank you!
why not register a global step and then put an if? example:
if something == true then
minetest.register_globalstep(function(dtime)
--Do stuff
end)
end
This is in the highest local space of a file called by dofile. It doesn't work though, the global step does not register. If you need more info just ask. This is probably simple so please forgive my naive question.
Thank you!
why not register a global step and then put an if? example:
minetest.register_globalstep(function(dtime)
if something == true then
--Do stuff
end
end)
it should do what you want
Yeah, it is what I suggested. It IS the cleaner way. Bool checks are lightning fast, anyways, and ability to alter settings at runtime is probably worth it