int Karn = 12; int Bleu = 17; ffc script KarnIncreaseBy3IfLeftPressed { void run() { while(true) { if (Karn != 21) { if (Link->PressLeft) { Karn += 3; } } else if (Karn == 21) { Link->HP = 0; } Waitframe(); } } } global script IfAPressIncreaseBleuBy7 { void run() { while(true) { if (Bleu != 31) { if (Link->PressA) { Bleu += 7; } } else if (Bleu == 31) { Link->HP = 0; } Waitframe(); } } }Would up above example code work perfectly or how would I change up above example code to work properly?
How can I ensure while and if loops work perfectly?
#1
Posted 11 August 2018 - 03:50 PM
#2
Posted 11 August 2018 - 03:58 PM
That should work, but the Karn will only work on the screen you put it on, while the Bleu will be running constantly. The loops should work fine though.
#3
Posted 11 August 2018 - 04:14 PM
It should work, although you're making the check every frame (every 60th of a second) so the player will probably die just as surely as if you killed him directly whenever he presses the left key.
Note that these global variables aren't reset when the player dies, so, should you resume playing, the variables will still be equal to the value that made the player die, and he will die again immediately.
You also don't need to specify the else if (...) condition in this case, since if, say "Karn != 21" is false, then the only possible reason is that "Karn" is equal to 21. So a simple "else { ... }" will suffice.
Edited by Jamian, 11 August 2018 - 04:16 PM.
#4
Posted 11 August 2018 - 04:23 PM
#5
Posted 12 August 2018 - 01:06 PM
If you want to know if something is working as you intend, issue raceS(string[]) and Trace(value) instructions...
const int DEBUG = 1; ffc script KarnIncreaseBy3IfLeftPressed { void run() { while(true) { if (Karn != 21) { if ( DEBUG ) { int s[]="Karn != 21."; int s1[]="Karn is now: "; TraceNL(); TraceS(s); TraceNL(); TraceS(s1); Trace(Karn); } if (Link->PressLeft) { if ( DEBUG ) { int s2[]="Player pressed LEFT."; TraceNL(); TraceS(s2); } Karn += 3; int s3[]="Karn is now: "; TraceNL(); TraceS(s3); Trace(Karn); } } else if (Karn == 21) { Link->HP = 0; if ( DEBUG ) { int s4[]="Karn == 21."; int s5[]="Link->HP is: "; TraceNL(); TraceS(s4); TraceNL(); TraceS(s5); Trace(Link->HP); } } Waitframe(); } } }
It should work, although you're making the check every frame (every 60th of a second) so the player will probably die just as surely as if you killed him directly whenever he presses the left key.
Note that these global variables aren't reset when the player dies, so, should you resume playing, the variables will still be equal to the value that made the player die, and he will die again immediately.
You also don't need to specify the else if (...) condition in this case, since if, say "Karn != 21" is false, then the only possible reason is that "Karn" is equal to 21. So a simple "else { ... }" will suffice.
Hard for me to say what the intended behaviour is, if Karn > 21. :;/
Moreover, if is not a loop type: It's a statement type.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users