Difference between revisions of "Random integer"

From HIVE
Jump to navigation Jump to search
m (1 revision: StarEdit.net Wiki)
m (Updated BBcode to new site.)
 
(3 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
== Pick + Withdraw ==
 
== Pick + Withdraw ==
 
If you want the editor to pick number 1-3, assign it to a random player, and then force it to pick a new value from the remaining values between 1-3, and assign it to a player that has been assigned no units:
 
If you want the editor to pick number 1-3, assign it to a random player, and then force it to pick a new value from the remaining values between 1-3, and assign it to a player that has been assigned no units:
 
+
http://omegacode.0sites.org/BBCode/BBCode3.php?ID=17
http://vgshorts.com/BBCode/BBCode3.php?ID=17
+
{{Trigger
Pick random stuff
+
|variables=*Successful Attempts = 0 <Integer>
  Events
+
*Choices = false <Boolean[3]>
  Local Variables
+
*Players = false <Boolean[3]>
      Successful Attempts = 0 <Integer>
+
*SelectedChoice = 0 <Integer>
      Choices = false <Boolean[3]>
+
*SelectedPlayer = 0 <Integer>
      Players = false <Boolean[3]>
+
|actions=General - For each integer Successful Attempts from 1 to 3 with increment 1, do (Actions)
      SelectedChoice = 0 <Integer>
+
:Actions
      SelectedPlayer = 0 <Integer>
+
::Pick the unit choice
  Conditions
+
::Variable - Set SelectedChoice = (Random integer between 0 and 2)
  Actions
+
::General - While (Conditions) are true, do (Actions)
      General - For each integer Successful Attempts from 1 to 3 with increment 1, do (Actions)
+
:::Conditions
          Actions
+
::::Choices[SelectedChoice] == true
              ------- Pick the unit choice
+
:::Actions
              Variable - Set SelectedChoice = (Random integer between 0 and 2)
+
::::Variable - Set SelectedChoice = (Random integer between 0 and 2)
              General - While (Conditions) are true, do (Actions)
+
::------- Pick the player number
                  Conditions
+
::Variable - Set SelectedPlayer = (Random integer between 0 and 2)
                      Choices[SelectedChoice] == true
+
::General - While (Conditions) are true, do (Actions)
                  Actions
+
:::Conditions
                      Variable - Set SelectedChoice = (Random integer between 0 and 2)
+
::::Choices[SelectedChoice] == false
              ------- Pick the player number
+
:::Actions
              Variable - Set SelectedPlayer = (Random integer between 0 and 2)
+
::::Variable - Set SelectedPlayer = (Random integer between 0 and 2)
              General - While (Conditions) are true, do (Actions)
+
::------- Actions
                  Conditions
+
::------- Do All the unit spawning stuff here ------
                      Choices[SelectedChoice] == false
+
::Variable - Set Choices[SelectedChoice] = true
                  Actions
+
::Variable - Set Players[SelectedPlayer] = trueffs
                      Variable - Set SelectedPlayer = (Random integer between 0 and 2)
+
}}
              ------- Actions
 
              ------- Do All the unit spawning stuff here ------
 
              Variable - Set Choices[SelectedChoice] = true
 
              Variable - Set Players[SelectedPlayer] = true
 
  
 
== Limitations ==
 
== Limitations ==

Latest revision as of 09:53, 2 May 2011

The random integers have a lot of applications. This wiki will try to give trigger references for the most common on them.

Pick + Withdraw

If you want the editor to pick number 1-3, assign it to a random player, and then force it to pick a new value from the remaining values between 1-3, and assign it to a player that has been assigned no units: http://omegacode.0sites.org/BBCode/BBCode3.php?ID=17

StarCraft 2 Trigger [template]
Events:

None.

Variables:
  • Successful Attempts = 0 <Integer>
  • Choices = false <Boolean[3]>
  • Players = false <Boolean[3]>
  • SelectedChoice = 0 <Integer>
  • SelectedPlayer = 0 <Integer>
Conditions:

None.

Actions:

General - For each integer Successful Attempts from 1 to 3 with increment 1, do (Actions)

Actions
Pick the unit choice
Variable - Set SelectedChoice = (Random integer between 0 and 2)
General - While (Conditions) are true, do (Actions)
Conditions
Choices[SelectedChoice] == true
Actions
Variable - Set SelectedChoice = (Random integer between 0 and 2)
------- Pick the player number
Variable - Set SelectedPlayer = (Random integer between 0 and 2)
General - While (Conditions) are true, do (Actions)
Conditions
Choices[SelectedChoice] == false
Actions
Variable - Set SelectedPlayer = (Random integer between 0 and 2)
------- Actions
------- Do All the unit spawning stuff here ------
Variable - Set Choices[SelectedChoice] = true
Variable - Set Players[SelectedPlayer] = trueffs


Limitations

While short and sweet, this trigger segment can be subject to long running times if a number is repeatedly picked by the random integer function (as it will pick it, realize it has been picked, and then re-pick over and over again). While it will generally not be noticeable, as the triggers run quite fast, bear in mind that using large choice or player integer values can cause this script to lag. It is better suited to values of about 15 or below.