coding problem with "while"
thierry_st_malo
18 Apr 2016, 15:46As far as I understand things, this code
game.mode = 0
while (game.mode <> 3) {
wait {
msg ("Coucou !")
}
game.mode = game.mode + 1
}
should loop three times, every time waiting for a key press, and then printing "Coucou !"
Yet I get an error message stating that only one wait can run at a time. How come ?
Thanks in advance,
Thierry
game.mode = 0
while (game.mode <> 3) {
wait {
msg ("Coucou !")
}
game.mode = game.mode + 1
}
should loop three times, every time waiting for a key press, and then printing "Coucou !"
Yet I get an error message stating that only one wait can run at a time. How come ?
Thanks in advance,
Thierry
thierry_st_malo
18 Apr 2016, 17:41I have tried moving the "game.mode = game.mode + 1" into the inside pair of curly braces. Same result.
HegemonKhan
18 Apr 2016, 19:29because 'wait' doesn't pause/halt the 'while' looping, thus, you get a second activated 'wait' at the same time the first 'wait' is waiting for the person to press a key, which (having two 'waits' at the same time) can't occur, thus the error.
quest doesn't have a good 'while-looping' programmed system, epsecially with it usually being so reliant upon user inputs or popup windows (as these are useful functions for game makers to use).
just use recursion looping instead, but just make sure you don't allow it to build up, obviously.
recursion looping:
if you want to see more examples of recursion looping:
viewtopic.php?f=18&t=4988
--------------
if you need to use 'get input', 'show menu', and/or 'wait', then you can't use 'while' and general looping. You must use recursion looping and 'if' Scripts.
Otherwise, you can use 'while' and general looping. However, (in my ignorance), I've not come across many times where you'd need to apply 'while' and generalized looping.
quest doesn't have a good 'while-looping' programmed system, epsecially with it usually being so reliant upon user inputs or popup windows (as these are useful functions for game makers to use).
just use recursion looping instead, but just make sure you don't allow it to build up, obviously.
recursion looping:
<function name="whatever_function">
if (game.mode < 3) {
wait {
msg ("Coucou!")
game.mode = game.mode + 1
whatever_function // putting this here, so you don't have an infinite loop, but you can adjust this entire code for what you want to do
}
}
</function>
if you want to see more examples of recursion looping:
viewtopic.php?f=18&t=4988
--------------
if you need to use 'get input', 'show menu', and/or 'wait', then you can't use 'while' and general looping. You must use recursion looping and 'if' Scripts.
Otherwise, you can use 'while' and general looping. However, (in my ignorance), I've not come across many times where you'd need to apply 'while' and generalized looping.