Jump to content

Parse error: parse error, unexpected T_BOOLEAN_OR


mforan

Recommended Posts

hi there, im having problems with this code:

[color=blue]if ( (($buildchange[6] != "0") && ($buildchange[6] != "")) && ($info[8] == "Private")) ||

(($buildchange[7] != "0") && ($buildchange[7] != "")) && ($info[8] == "Private") || ($info[8] == "Captain") || ($info[8] == "Major") || ($info[8] == "Lt. Colonel") || ($info[8] == "Colonel")) ||

(($buildchange[8] != "0") && ($buildchange[8] != "")) && ($info[8] == "Private") || ($info[8] == "Captain") || ($info[8] == "Major") || ($info[8] == "Lt. Colonel") || ($info[8] == "Colonel") || ($info[8] == "Major General")) ||

(($buildchange[9] != "0") && ($buildchange[9] != "")) && ($info[8] == "Private") || ($info[8] == "Captain") || ($info[8] == "Major") || ($info[8] == "Lt. Colonel") || ($info[8] == "Colonel")) || ($info[8] == "Major General")) || ($info[8] == "Lt. General")) ) {

$done = false;
$excuse = "Damn hacker, cant build those till you improve";
} else {[/color]

i keep getting the error: Parse error: parse error, unexpected T_BOOLEAN_OR

can anyone help here?
Wow, that's not exactly the easiest code to read through. Anyway at the end of the first [b]$info[8] == "Colonel"[/b] there are two right parens. The 2nd one closes the if conditional. In fact you have an extra right paren at the end of each line after that as well.

By the way you could easily condense some of this. For example, you could change this:
[code]if (($buildchange[6] != "0") && ($buildchange[6] != ""))[/code]

To this:
[code]if ($buildchange[6])[/code]

Which means that the variable has a value and it is not false or 0.
The problem here is your coding style.. it's terrible :)

You can make things clearer with this technique:

[code=php:0]$change6_bad = (($buildchange[6] != "0") && ($buildchange[6] != "")) && ($info[8] == "Private"));
$change7_bad = (($buildchange[7] != "0") && ($buildchange[7] != "")) && ($info[8] == "Private") || ($info[8] == "Captain") || ($info[8] == "Major") || ($info[8] == "Lt. Colonel") || ($info[8] == "Colonel"));
# and so on for each, then
if ($change6_bad || $change7_bad | ... ) {
}[/code]


You may want to split it up even more.  One thing you could use is a "rank_greater_than()" function, instead of doing all those individual tests.  That will make the code much clearer.  And with clearer code, you will notice syntax errors much more easily.

[code=php:0]if ((($buildchange[6] != "0") && ($buildchange[6] != "")) && !rank_greater_than($info[8], 'Private')) || ...[/code]
yep yep yep, well i didnt program it you see. but i do agree it could be layed out a bit better.

the guy that originally programmed it was ameteur his self i belive. much like my self!


well thanks guys, using some of the things you said i got it working. cheers  ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.