Adding an item randomly from a list

Quick question.

In Zmud I used to have a script where I had a few items hard coded into a list (rum,whiskey,ale for example.) and an alias to call any of those at random when required. So when I called the alias I would drink one of those randomly.

So ^dd$
Send("Drink " (on of above randomly))

Can't quite figure this out in Mudlet, any help would be nice :)


(Party): Mezghar says, "Stop."


  • In a script somewhere, store the list of items in a table: 
     drinks = {"rum","whiskey","ale"}

    Then in the script for your alias:
      local whichdrink = math.random(1,#drinks)
      send("drink "..drinks[whichdrink])

    If you prefer, you can define the list directly in the alias, in which case I'd make it a local:
      local drinks = {"rum","whiskey","ale"}
      local whichdrink = math.random(1,#drinks)
      send("drink "..drinks[whichdrink])

    The latter version has the disadvantage of the added overhead of defining the table every time you call the alias (if this ever affects you noticeably, I'll fly to the UK just to buy you a drink) and the advantage of not having to worry about giving the variable a name that won't conflict with things in other scripts.
  • Thank you :). I'll give it a try

    (Party): Mezghar says, "Stop."
Sign In or Register to comment.