• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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

Evanski

Raccoon Lord
Forum Staff
Moderator
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.
 
Last edited by a moderator:
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