Legacy GM (Solved) Can a variable pick a string at random?

EvanSki

King of Raccoons
Basically what I want to do is

Have an object call a script (scr_decry)
The script holds a variable (decry_phrase) and a list of strings such as "apple", "password","pinepplesarebad"
Then the script will make (decry_phrase) = a random string from the list

Any help is appreciated, Thanks!
 

chamaeleon

Member
Basically what I want to do is

Have an object call a script (scr_decry)
The script holds a variable (decry_phrase) and a list of strings such as "apple", "password","pinepplesarebad"
Then the script will make (decry_phrase) = a random string from the list

Any help is appreciated, Thanks!
Not entirely sure what you really want to do in your script, but perhaps choose() would be suitable for your needs, if the set of strings is fixed at compile-time. Otherwise, store the strings in a ds_list and use ds_shuffle() and pick the first entry as the chosen string.
 
Arrays or ds_lists could be used in this case.

Code:
/// scr_decry()

var index = 0;

var decry_phrase[index++] = "Apples";
decry_phrase[index++] = "password";
decry_phrase[index++] = "pinepplesarebad";

var selection = irandom_range(0, array_length_1d(decry_phrase) - 1)

return ( decry_phrase[selection] )
 
Top