UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050403 
Galeon/1.3.20
IP: 128.83.113.38
URI: http://wesnoth.slack.it/?ProbabilityBasedBranching
 - - - - -
Here is code that lets you specify a probability for doing something:

||Examples of use||

||Example 1:|| Do something common with an 85% chance, otherwise do something 
uncommon. Your code doesn't have to be a
macro; I just show some bogus macros for brevity.

 {PERCENT_CHANCE 85}
    {YOUR_CODE_HERE}               # 85% chance of being executed
 {PERCENT_CHANCE_ELSE}
    {YOUR_OTHER_CODE_HERE}         # executed if-and-only-if the previous one 
wasn't
 {PERCENT_CHANCE_END}

||Example 2:|| Do something with a 37% chance, otherwise do nothing.

 {PERCENT_CHANCE 37}
    {YOUR_CODE_HERE}               # done with an 37% chance; otherwise nothing 
happens at all
 {PERCENT_CHANCE_END_WITHOUT_ELSE} # notice that you have to use a different 
terminator

||The Macro Definitions:||

 
#===============================================================================
 # Macros for probability-based branching:
 
#-------------------------------------------------------------------------------
 #define PERCENT_CHANCE PERCENT
    {RANDOM 1..100}
    [if]
       [variable]
          name=random
          less_than_equal_to={PERCENT}
       [/variable]
    [then]
 #enddef
 #define PERCENT_CHANCE_ELSE
    [/then]
    [else]
 #enddef
 #define PERCENT_CHANCE_END
    [/else]
    [/if]
 #enddef
 
#-------------------------------------------------------------------------------
 # For when you don't want an 'else':
 #define PERCENT_CHANCE_END_WITHOUT_ELSE
    [/then]
    [/if]
 #enddef


||See Also||

* UsefulWMLFragments




_______________________________________________
Wesnoth-wiki-changes mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/wesnoth-wiki-changes

Reply via email to