Now that you have it fixed, I will explain why that
else if wouldn't have worked (even if you had kept your spacing correct):
if (condition) { randattack }
else if (condition2) { attackplayer $2 }
[color:red]else { msg $chan Not found. }[/color]
That red ELSE line will never ever be run because it has no matching IF.
As you had it written, it would have looked like this using all the braces and separate lines to show it more clearly:
if (condition1) {
randattack
}
else {
if (condition2) {
attackplayer $2
}
}
else {
msg $chan Not found.
}
Notice that you have 2 else's, one after the other, there. The second one has no IF associated with it, therefore it can never get executed. If you wanted it to go with if (condition2) and both of them under the else, then you have to group them with { }, like this:
if (condition1) { randattack }
else {
if (condition2) { attackplayer $2) }
else { msg $chan Not found. }
}
else if is NOT the same thing as
elseif.
- if (this condition works) { do this }
; Ok, that one didn't work, let's try a different condition
elseif (a different condition works) { do that }
; Well, none of the above worked, so do this last thing in an "otherwise" condition
else { do something else entirely }
Control drops out of the IF-ELSEIF-ELSE structure when it finds its first matching ($true) condition. The others are not even tested or considered at all. So, if the IF condition works, ELSEIF and ELSE are completely disregarded. If the IF fails, then the ELSEIF condition is tested and, if it is true, then the code in the ELSEIF block is executed and the ELSE section is completely disregarded. If neither the IF nor the ELSEIF match, then the ELSE code is executed.
The main function of { } is to group multiple commands, either on a single line separated by | or on multiple lines; in the case of multiple commands, { } are
required to group all the commands into a block. They are not required for a single command on the same line; that is why I repeatedly removed them from my example code. They are required for anything that is multi-lined, single command or multiple commands. (Note that this is not the same thing at all as $&, which is line continuation ... continuing the
same line on the next line but still treating it as if it were all on one line, which is used for readability for very long script lines.)