1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 (Solved) Can a variable pick a string at random?

Discussion in 'Programming' started by EvanSki, Aug 15, 2018.

  1. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    581
    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!
     
  2. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    1,100
    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.
     
    EvanSki likes this.
  3. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,389
    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] )
    
     
    EvanSki likes this.

Share This Page