Welcome to the Achaea Forums! Please be sure to read the Forum Rules.

random variable

KoeKoe Posts: 6
I'm hoping to create a function where my alias will select random abilities from a table, I can get it to take the value from the table but not to cycle through the variables(only two right now for simplicity). What is it missing?



function mentalafflictions()

mental_affliction = {"limerick", "pastorale"}

       send("sing "..mental_affliction[1].." at "..target.."")

end


Best Answers

  • CrixosCrixos Posts: 39 ✭✭✭ - Distinguished
    edited March 2014 Accepted Answer
      send("sing "..mental_affliction[1].." at "..target.."")

    In this line you're selecting the first entry from the table, "mental_affliction[1]"

    Try,

    send("sing "..mental_affliction[math.random(2)].." at "..target.."")

    Using the math.random, it should give you a random number between 1..2



    Koe
  • NimNim Posts: 2,015 @@ - Legendary Achaean
    Accepted Answer
    If you want it to be extendible to any array size, you could also use math.random(#<array>), eg. in this case

    send("sing "..mental_affliction[math.random(#mental_affliction)].." at "..target.."")
    FeralKoe

Answers

  • KoeKoe Posts: 6
    Crixos said:
      send("sing "..mental_affliction[1].." at "..target.."")

    In this line you're selecting the first entry from the table, "mental_affliction[1]"

    Try,

    send("sing "..mental_affliction[math.random(2)].." at "..target.."")

    Using the math.random, it should give you a random number between 1..2



    Perfect! Thank you so much.
Sign In to Comment.