Author Topic: VCE Random Event  (Read 1890 times)

The following describes VCE version 6.10, your experience may differ depending upon your version.
To determine your environment's VCE version: Wrench and open an event window, click the (VCE Client) button at the top. Then click on (changelog) and read for the latest version mentioned.


RANDOM:
The VCE random function has two modes of operation.
The first will generate a random decimal between but not including zero and one.
The second is a convenience function that will select a positive integer from a selected range.

How to set the RANDOM mode:
Random will read the modVariable's existing value to determine its mode.

  • If the modVariable does not exist yet: the default mode will generate a decimal number between 0 and 1.
  • If the modVariable contains a negative number: the default mode will generate a decimal number between 0 and 1.
  • If the modVariable contains a decimal number: the default mode will generate a decimal number between 0 and 1.
  • If the modVariable already exists and contains a whole number (0 1 2 3…)  then random will read that number as the min, Random's parameter as the maximum, and randomly select an integer within that range.


Wrench a nearby brick and enter these events. Then un-equip and click on it.

Code: [Select]
[x]0  [0   ][onActivate ][Client ][ChatMessage      ][Begin <var:global:time>  ]
[x]1  [0   ][onActivate ][Client ][ChatMessage      ][Initially generatednumberA is <var:brick:generatednumberA> ]
[x]2  [0   ][onActivate ][Self   ][VCE_modVariable ][Brick ][generatednumberA      ][Random ][4   ]
[x]3  [0   ][onActivate ][Client ][ChatMessage      ][Afterward generatednumberA is <var:brick:generatednumberA> ]
[x]4  [0   ][onActivate ][Client ][ChatMessage      ][------Finished------ ]
[x]5  [0   ][onActivate ][Client ][ChatMessage      ][   put a space in this box  ]
[x]6  [0   ][onActivate ][Self   ][VCE_modVariable ][Brick ][generatednumberA      ][Set    ][-2    ]

Note the first time thru the variable has not been created yet. Click the brick and run it a few times.
On Line 6, change the SET value to see how pre-setting the variable changes the output.
On Line 2, change the maximum Random value. Note it is ignored if default mode is used.
Use your pageUp and PageDn keys to scroll the chat area.

The convenience/integer range mode is the most common way RANDOM is used in Blockland.
You must preset the modVariable (in a prior event line) to enable output greater than 1 and match the examples.
Common values to preload are zero and one. The stored number becomes your minimum. The number you entered after the random command becomes your maximum value. The resulting random whole number will be Set on the modVariable, completely replacing the previous contents.


Please put [Tutorial] before the subject.