×
Меню
Индекс

MSFD Assigning random values to variables

 
[no fix] Random, value_enum
 
     Set my_variable to Random, 50
 
Introducing some unpredictability into the effects of a script is a nice option, and it can be done with the Random function. Random returns values between 0 and the set value –1. So in the example above, my_variable will be set to a value in the range from 0 to 49.
Note that the global short variable Random100 gets set each frame by the game's Main script to a random value between 0 and 100 (inclusive), so you can make use of that one, too.
Note that if you are using random100 in dialogue, you may want to add:
set random100 to random, 101
in the resultbox so that random100 is reset for the next topic chosen. Main does not set random100 in menumode.
 
Note: For any call to Random with a range over 100, the randomosity of the return value gets very poor indeed... right up to Random, 255 where you only get 0 or 1... and any multiple of 256 also gets you a CTD. (Morrowind and Tribunal). In Bloodmoon, they seem to have fixed the randomosity of the return value... you seem to get numbers that are more evenly distributed, even with a range above 100. But the CTD's at 256 and 512, etc, still happen (Info by Neko). It was furthermore discovered that sometimes the Random cap is set much higher than the number given. Setting any variable to a Random with the cap value of one of the following numbers produces some strange result, setting the higher cap actually to something around 1100: 65, 66, 68, 70, 71, 76, 77, 79, 82, 83, 84
 
TunaandCheese suggests that a method to work arround the poor randomosity in Morrowind and Tribunal is to merge Random results, as is demonstrated in this script:
 
begin randomnumber
 
;this script works out a random number between 0 and 10000
 
short spare
short number
 
;works out how many thousands there are
set number to random, 10
set number to ( number * 1000 )
 
;how many hundrerds
set spare to random, 10
set spare to ( spare * 100 )
set number to ( number + spare )
 
;and how many tens
set spare to random, 10
set spare to ( spare * 10 )
set number to ( number + spare )
 
;this has to be random, 11, rather than random, 10 as if it was random 10,
;it would only be 0 - 9999
set spare to random, 11
set number to ( number + spare )
 
;the variable number now contains a random number between 0 and 10,000 that you can use
 
end