UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050403 Galeon/1.3.20 IP: 128.83.57.150 URI: http://wesnoth.slack.it/?CaseBasedReasoningB - - - - - Index: CaseBasedReasoningB =================================================================== RCS file: /home/wesnoth/cvsroot/wikiroot/CaseBasedReasoningB,v retrieving revision 1.1 diff -u -r1.1 CaseBasedReasoningB --- CaseBasedReasoningB 4 May 2005 19:25:08 -0000 1.1 +++ CaseBasedReasoningB 6 May 2005 12:24:49 -0000 @@ -1,76 +1 @@ -Use this to make deeply nested if-then-else logic look slightly more like a case statement. - -||Example of Use|| - -For brevity the code to be executed is shown as macros in this example, but you can put raw WML there if you wish. - - # A unit finds a treasure... or something. - {RANDOM 1..100} - {IF_RANDOM_LE 40} # 40% chance - {FIND_TRASH} # your code here... - {ELSE_IF_RANDOM_LE 65} # 25% chance - {FIND_GOLD} - {ELSE_IF_RANDOM_LE 85} # 20% chance - {FIND_POTION} - {ELSE_IF_RANDOM_LE 95} # 10% chance - {FIND_WEAPON} - {ELSE_IF_RANDOM_LE 99} # 4% chance - {FIND_MONSTER} - {ELSE_IF_RANDOM_LE 100} # 1% chance - {FIND_REALLY_BAD_MONSTER} - [/then] - [else] - # This is a saftey check. It's not really needed here, but I left it in - # to show how to trap everything >= the final ELSE_IF bracket. - # Otherwise, you should use [/if] rather than [else] here. See the related - # example at "Case Based Reasoning A" (link is at "See Also", below). - [message] - speaker=narrator - message="Error: Random number > 100 in DISCOVER_SOMETHING" - [/message] - {CLOSE_ELSE_IF} - {CLOSE_ELSE_IF} - {CLOSE_ELSE_IF} - {CLOSE_ELSE_IF} - {CLOSE_ELSE_IF} - {CLOSE_ELSE_IF} - -If you can figure out a way to get rid of all the CLOSEs, replace this code with yours! - -||The Macro Definitions|| - - #=============================================================================== - # Macros to make deep-nested if statements clearer: - #------------------------------------------------------------------------------- - # For testing less-than-or-equal-to: - #define IF_RANDOM_LE VALUE - [if] - [variable] - name=random - less_than_equal_to={VALUE} - [/variable] - [then] - #enddef - #define ELSE_IF_RANDOM_LE VALUE - [/then] - [else] - [if] - [variable] - name=random - less_than_equal_to={VALUE} - [/variable] - [then] - #enddef - #------------------------------------------------------------------------------- - #define CLOSE_ELSE_IF - [/else] - [/if] - #enddef - -N.B. - The CLOSE_ELSE_IF macro is also used in the macros for CaseBasedReasoningA, so if you use them both you don't -want to define it twice. - -||See Also|| - -* CaseBasedReasoningA -* UsefulWMLFragments +This page has been superceded by the macros at ProgrammingMacros.
_______________________________________________ Wesnoth-wiki-changes mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/wesnoth-wiki-changes
