Bolgo The Madd Posted May 3, 2006 Share Posted May 3, 2006 Hey, I remember reading somewhere, a long time ago, that there is a correct way to use else and/or elseif.Whats the deal? Is it always ElseIf but the very last one is Else?Most of the scripts that shipped with the game are so small I can't even find the proper convention! Just let me know. glut glutBolgo The Madd Link to comment Share on other sites More sharing options...
Myydraal Posted May 3, 2006 Share Posted May 3, 2006 Well the CS can be...unpredictible, or atleast seem that way. But this is the way *I* do it, whihc i think works most of the time.... if (condition) elseif(condition) elseif(condition) endif OR if(con) elseif(con) elseif(con) else endif You don;t have to have a else at the end, but u can, u can have as many else ifs that you want, from what i can tell atleast. oblvios u can have only one else per if....as that only makes sence. anyways hope this helps, and hey if it doesn;t work, blame the CS like i do =P Added- if/else blocks are good for lets saying checking to see if this condition is true and then run something, but in EVERY other case u want something ELSE to run. if/elseif blocks are good for let say checking a condition doing something maby and tehn checking a condition after u KNOW that the previos condition was not true and then running somethin, this can go on for as long as u want, and u can end it with an else statment if u still wanna catch all the other possiblitys that could exists, anyways i hope that was coherent =P Link to comment Share on other sites More sharing options...
howardb1 Posted May 19, 2006 Share Posted May 19, 2006 Hey, I remember reading somewhere, a long time ago, that there is a correct way to use else and/or elseif.Whats the deal? Is it always ElseIf but the very last one is Else?Most of the scripts that shipped with the game are so small I can't even find the proper convention! Just let me know. glut glutBolgo The Madd The following two structures are the same except for a detail I'll cover after the example. The first is simply a nesting of another If statement that is executed only if the first condition evaluates to false. The second statement performs the same way, but the ElseIf elimiate the nesting (and the indentation), also you only need one EndIf at the end of whole thing. If (Cond 1); Do someting (Condition 1 true)Else; Could do someting before (Condition 1 False)If (Cond 2); Do someting (Condition 1 False, but Condition 2 True)ElseIf (Cond 3); Do someting (Condition 1 and 2 are False, but Condition 3 True)Else; Do someting (Condition 1, 2, and 3 are False)End IfEndIF; Could do someting after (Condition 1 False)EndIf And If (Cond 1); Do someting (Condition 1 true)ElseIf (Cond 2); Do someting (Condition 1 False, but Condition 2 True)ElseIf (Cond 3); Do someting (Condition 1 and 2 are False, but Condition 3 True)Else; Do someting (Condition 1, 2, and 3 are False)EndIf The nested If-Else structure has two 'Could do something ...' comments in places you can't code in a pure If-ElseIf statement, making the If-Else structure a little bit more flexible. However, you can mix the two by nesting a IF-ElseIf inside of a If-Else structure, and visa versa, but this isn't often done as a matter of style. So if you do, use extra blank lines around the nested structure and maybe some sort of comment to help make it clear what you're trying to do. Also, as was already stated, you only need the Else if you want/need to handle the case where the condition evaluates to false, i.e.: If I have have a bow equiped, then equip arrows. This example probably wouldn't need an else, because if you don't have a bow equiped, then you don't need to do anything, script-wise atleast. Hopefully, I understood your question and didn't aim too low. :) Link to comment Share on other sites More sharing options...
matter2003 Posted May 27, 2006 Share Posted May 27, 2006 Hey, I remember reading somewhere, a long time ago, that there is a correct way to use else and/or elseif.Whats the deal? Is it always ElseIf but the very last one is Else?Most of the scripts that shipped with the game are so small I can't even find the proper convention! Just let me know. *********************************************************************************** You should use ElseIf when you have more than two conditions you are checking for. For example: Let's say you want to set a spell based on what level the player is. You want to have it so that there are for seperate spells, for different level ranges. Not sure what the script code would be, but it would be similar to this: If PlayerLevel <25 **Do Something** ElseIf PlayerLevel <50 **Do Something Else** ElseIf PlayerLevel <75 **Do Something Else** ElseIf PlayerLevel <100 **Do Something Else** -note that its important to put them in the correct order, since only one condition will be checked for. If the player is at level 15, it will terminate the If..ElseIf statement at the first condition check(Level 25). You could also use if PlayerLevel >25 and <50, but its not necessary to do so. You should use Else when you want to check for a condition or conditions, but then if all of the conditions checked for are false, it will default to running the code under Else. An Exmaple is: If PlayerLevel <25 **Do Something** ElseIf PlayerLevel <50 **Do Something Else** Else **Do Something Else** The "Else" part will always run when the PlayerLevel is 50 or higher, because it acts as a sort of funnel for any condition that is not true in the other conditions. Think of it as saying If Something=True then do this, ELSE if something is false do that, whereas ElseIf is still looking for a condition to be true for it to run, and will not run if it is false. With an Else command in there, you will always have at least one statement run, with an ElseIf, it only runs when the condition is true. Sorry about the lnog and possibly confusing explanation... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.