Ifrnd: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Plugwash (talk | contribs)
No edit summary
ifrnd: correct probabilities
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
ifrnd <value> { <do somethin!> }
'''ifrnd''' <value> { do something } else { do something else }


An [[if condition]] stating the probability of it 'doin somethin!' in this case.
An [[if condition]] stating the probability of it 'doin somethin!' in this case.


NOTE: It's out of 256 as max, so 'ifrnd 256 = 100%', and 'ifrnd 128 = 50%'
A <value> greater or equal to 255 corresponds to a 100% probability that the first block is taken. With a <value> of -1, the "else" block is taken every time. (A <value> of 0 means taking the "if" block once out of 256 on average).


This command must only be used in synchronised code or you will cause desyncs. for display code use [[displayrand]] instead.
This command must only be used in synchronised code or you will cause desyncs. for display code use [[displayrand]] instead.
[[Category:Duke3D 1.3/1.5 commands]]
[[Category:If conditions]]

Latest revision as of 12:38, 6 June 2012

ifrnd <value> { do something } else { do something else }

An if condition stating the probability of it 'doin somethin!' in this case.

A <value> greater or equal to 255 corresponds to a 100% probability that the first block is taken. With a <value> of -1, the "else" block is taken every time. (A <value> of 0 means taking the "if" block once out of 256 on average).

This command must only be used in synchronised code or you will cause desyncs. for display code use displayrand instead.