Randvar: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
mNo edit summary
m clarify rand range
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:
'''randvarvar''' <gamevar> <value>
'''randvarvar''' <gamevar> <value>


This function generates a random number from 0 to <value> and assigns it to <gamevar>.
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.
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.
Line 8: Line 8:
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.
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 [[gamevar]]s rather than constants or [[define]]d labels for their inputs.
{{varsuffix}}


[[Category:EDuke commands]]
[[Category:EDuke commands]]
[[Category:Gamevar manipulation]]
[[Category:Gamevar manipulation]]

Revision as of 14:10, 2 August 2020

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.