Randvar: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Plugwash (talk | contribs)
No edit summary
 
mNo edit summary
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
'''randvar''' and '''randvarvar''' generate a random number and put it in a variable.
<span {{code}}>'''rand''' <gamevar> <value></span>


randvar and randvarvar MUST NOT be used in unsynchronised code or you will get a desync. furthermore this desync is insiduous and won't appear immidiately but only the next time the random number generator is used for its proper function.
<span {{code}}>'''randvar''' <gamevar> <value></span>


in the official eduke releases and many modified versions (including current releases of eduke32) this is broken and use will desync multiplayer
<span {{code}}>'''randvarvar''' <gamevar> <value></span>


we have now fixed it
This function generates a random number (using the shared "game" PRNG) from 0 to <value> (inclusive), and assigns it to <gamevar>.
 
This command should not be used in unsynchronized code or it will desynchronize multiplayer games.  See the list of [[unsynchronized events]] for a full list.
 
In prior releases of DOS EDuke, randvar contained a flaw that would desynchronize multiplayer regardless of where the command was used.  The bug has since been corrected for post-1.0 releases of EDuke32.
 
{{varsuffix}}
 
[[Category:EDuke commands]]
[[Category:Gamevar manipulation]]

Latest revision as of 05:17, 12 January 2021

rand <gamevar> <value>

randvar <gamevar> <value>

randvarvar <gamevar> <value>

This function generates a random number (using the shared "game" PRNG) from 0 to <value> (inclusive), and assigns it to <gamevar>.

This command should not be used in unsynchronized code or it will desynchronize multiplayer games. See the list of unsynchronized events for a full list.

In prior releases of DOS EDuke, randvar contained a flaw that would desynchronize multiplayer regardless of where the command was used. The bug has since been corrected for post-1.0 releases of EDuke32.

Commands with an additional "var" suffix take gamevars rather than constants or defined labels for their inputs. As an alternate short form, "varvar" can be dropped from these commands; for example ife serves an an alias for ifvarvare.