How do you wait in Mage’s might?
I can’t import time, and if I try to run a loop using the hero.time, it keeps saying there is an infinite loop.
How do you wait in Mage’s might?
I can’t import time, and if I try to run a loop using the hero.time, it keeps saying there is an infinite loop.
Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!
What do u mean? (20000)
can’t you just use hero.wait(1)
?
The way you can wait is by setting a variable to the current time plus however much you want to wait for and check if the current time is greater than the variable.
Codecombat does not provide the time module, and Mages’ Might does not provide the .wait()
function.
CodeCombat intercepts your while loops and artifically adds a one-tick delay between iterations. That’s why the code forever: do nothing
runs fine.
To wait time, just cycle through a while-true loop doing nothing, and the one-tick delays add up. You can either do this in your main loop as JWH suggests or with a utility function to wait inline:
// JS
function delay(ticks) {
while (true)
if (!(ticks --))
break;
}
It’s strange, because there’s already hero.now()/hero.time() in CodeCombat, but it’s not usable in Mage’s Might.