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

Adding an item randomly from a list

SobriquetSobriquet Member Posts: 2,422 @@ - Legendary Achaean
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 :)

Ta
image

Comments

  • EldEld Member Posts: 3,946 @@ - Legendary Achaean
    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.
    Sobriquet
  • SobriquetSobriquet Member Posts: 2,422 @@ - Legendary Achaean
    Thank you :). I'll give it a try
    image
Sign In to Comment.