Quote:
Originally Posted by Gambet
Consecutive if statements without using else if is improper programming. Although it works fine in GScript, if you tried programming like that in other languages, the compiler would report errors.
|
Um, what? There is nothing wrong with consecutive if statements if the situation calls for it. It should never error, unless you are referring to a lack of end if/end/fi/whatever (which is a minority of languages)
This is valid php code that is necessary to use two consecutive ifs to do what it needs to do (granted it is pointless)
PHP Code:
if ($i < 3) {
$text .= "This number is less then 3. ";
}
if ($i > 1) {
$text .= "This number is greater then 1. ";
}
print $text;
Quote:
Originally Posted by Gambet
Also, to help prevent possible glitching, you should take the absolute value of the donated amount and then run your checks from there. I see that you do have a > 0 check, but you don't have any else statements in the code which makes it not-so user friendly when it comes to the script reporting proper syntax for players that use the donate command improperly.
|
Um, why? Absolute value? He should just give an error message for anything less then 0 and that is it.
Quote:
Originally Posted by Inverness
I'm quite familiar with the advantages of nested if statements. My case only applies if there is no else or leading or following statements around the nested if statement.
|
Your case is still wrong (as PFA already pointed out). You don't need an else to justify nested if statements. You should nest if statements if they don't follow the same logical flow. It makes no difference to the compiler so why not make it more readable?
PHP Code:
// This rules
if (player.chat == "let us do this") {
if(player.x > 30 && player.y > 40) {
//stuff
}
}
// This sucks
if (player.chat == "let us do this" && player.x > 40 && player.y < 30) {
//stuff
}