Welcome to the Builder Academy

Question Trigger of the Day - IF Example

More
14 Mar 2014 19:03 #4753 by Rumble
Code:
Name: 'IF Example', VNum: [ 22], RNum: [ 22] Trigger Intended Assignment: Mobiles Trigger Type: Greet , Numeric Arg: 100, Arg list: None Commands: * By Relsqui * First we set %anumber% to some number between 1 and 100. eval anumber %random.100% * Then the beginning of the if-block. if (%anumber% == 5) * The following commands are only executed if the above condition is true. * (That is, if %anumber% is equal to 5.) clap say It's your lucky day! say You picked my favorite number! * If those commands were executed, the program skips to the next end. * Otherwise, it looks for an elseif. elseif (%anumber% > 90) * To read the following commands, the program must have determined the * following: The first condition (%anumber% == 5) is false. * The second condition (%anumber% > 90) is true. emote shrinks down to the size of a mouse. say Squeak squeak squeak! * If the first elseif condition was also false, the program looks for the * next one. elseif (%anumber% < 10) * Here's a tricky one. * If %anumber% equals 5, the program will already have run the commands * immediately after the if-statement at the top. Therefore, the following * commands only run when: %anumber% is not five (failing the first check.) * %anumber% is not greater than 90 (failing the second check.) * %anumber% is less than 10 (passing the third check.) emote grows an elephant's nose. emote blows a mighty blast with %self.hisher% trunk. * And now, the default, when %anumber% fails all the above checks. else * Note that else has no condition. emote disappears in a cloud of blue smoke. %purge% %self% * For that to happen, all of this must be true: %anumber% is not five. * %anumber% is not greater than 90. %anumber% is not less than 10. If all * those conditions are met, the mob will disappear in a cloud of blue smoke. * Finally, please don't forget the all-important... end * Ends are good. They tell the program when the if-block is over. After any of * the above sets of commands runs, the program skips to the next end. * * Notes: * We could have omitted the else. If we had, and none of the conditions had * been met, no commands in the if-block would run. However, there can never be * more than one else. There is only one default. There must always be the same * number of if's and end's. We could have had any number of ifelses, from zero * on up. To summarize, here is the basic format of an if-block: * if (condition) * (commands) * elseif (condition) <---optional. 0 or more * (commands) * else <---optional. 1 or 0 * (commands) * end * * So the simplest possible if-block would be: * if (condition) * (commands) * end
If this was helpful please vote or leave a review for TBA.

Rumble
The Builder Academy
tbamud.com 9091
rumble@tbamud.com

Please Log in or Create an account to join the conversation.

Time to create page: 0.168 seconds