I've seen recently some if clauses where people haven't put braces around what's inside, such as Beefster's new roll script, Saffiths 'isSolid', pkmnfrk's sideview ladders, how does this work?
I thought all ifs, elses, fors and whiles had to have braces around them?
Also, I think I saw a 'do(){}' in the NeoFirst script file, what's all that about?
These are all cases of having a single line in each clause.
The idea is that the special structures (if, while, else, etc.) can only have one block each. Normally, a block is designated by the braces ({ and }), and you can only add one to each clause (else counts separately)
However, if you consider that each statement (i.e. line ending with a semicolon) is also a block in and of itself, then you'll see that the braces are unnecessary for a single line.
ahh, so:
if(x == 0) Game->PlaySound(1);
is fine, aswell as
if(x == 0){Game->PlaySound(1);}
but whereas:
if(x == 0){Game->PlaySound(1);
Link->HP = 16;}
is fine,
if(x == 0)Game->PlaySound(1);
Link->HP = 16;
is not?
Yeah, that seems right. I stumbled upon the else thing by accident(typo), and think I only use it in one place due to my compulsive urge to add more lines to stuff. I have no idea about "do" though. What script is that in?
I still have much to learn before I could handle stuff like this myself. I dont know where I can find a something like "A scripting tutorial for the dumbest people in the world like me" tutorial :P
Gleeok's got it right. ZScript follows C with regard to how ifs and loops (for and while) work.
OK, go to: http://www.j-factor.com/~l/zeldaclassic/NeoFirst.txt
and search 'do {' in the find function, _L_ seems to use it quite frequently.
Wait, he just appears to have put it round waitframe(); a lot 😕
do {
Waitframe();
} while (Link->InputA);
}
Huh.....well isn't that some shit right there.
Don't you just hate it when you think you've got quite a nice grasp of something, and then it suddenly turns into something completely different? 😱
What the hell does that do?!
I don't understand 'do', and that while loop either has nothing in it, or no parameters.
😞
EDIT: WAIT a minute!
does that read:
Do{this;}While(this);?
So
do{Waitframe();}
while(Link->InputA);
?
and if it is that, why not just put
while(Link->InputA){Waitframe();}
?
Joe123 wrote:ahh, so:
if(x == 0) Game->PlaySound(1);
is fine, aswell as
if(x == 0){Game->PlaySound(1);}
but whereas:
if(x == 0){Game->PlaySound(1);
Link->HP = 16;}
is fine,
if(x == 0)Game->PlaySound(1);
Link->HP = 16;
is not?
The last example is technically fine, it just doesn't work the way you think. It works like this:
if (x == 0) {
Game->PlaySound(1);
}
Link->HP = 16;
Joe123 wrote:Don't you just hate it when you think you've got quite a nice grasp of something, and then it suddenly turns into something completely different? 😱What the hell does that do?!
I don't understand 'do', and that while loop either has nothing in it, or no parameters.
😞
EDIT: WAIT a minute!
does that read:
Do{this;}While(this);?
So
do{Waitframe();}
while(Link->InputA);
?
and if it is that, why not just put
while(Link->InputA){Waitframe();}
?
Because, do{} while(); has a different meaning. than just while(){};
do{} while(); is guaranteed to run the block at least once. It runs the block, then checks the conditional. If it's true, then it runs the block again, etc, etc. If you just use while(){}, then if the condition is false to begin with, the code in the block will never run.
I forget if you can use the until() clause instead of while(), but it just means it'll run while the conditional is false (which means that you can just use while(!something))
pkmnfrk wrote:if you can use the until() clause instead of while(), but it just means it'll run while the conditional is false (which means that you can just use while(!something))
Not unless another dev has added that to language recently.