Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Table question

Table question

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Shady Stranger   USA  (45 posts)  Bio
Date Sun 31 Aug 2014 01:49 PM (UTC)

Amended on Sun 31 Aug 2014 01:52 PM (UTC) by Shady Stranger

Message
I am attempting to make a script for throwing darts. I have
got everything figured out except for the bullseye. I want
a bullseye to be rare so I put it in the table with the rest
of the numbers. The only problem with this is that it will
print display as a Single, Double or Triple Bullseye. How
do I ignore svalue in the script below if snumber =
bullseye?



  -- dart names
  local SNUMBERS = {"1", "1", "1", "1", "2", "2", "2", "2", "3", "3", "3", "3", "4", "4", "4", "4", "5", "5", "5", "5", "6", "6", "6", "6", "7", "7", "7", "7", "8", "8", "8", "8", "9", "9", "9", "9", "10", "10", "10", "10", "11", "11", "11", "11", "12", "12", "12", "12", "13", "13", "13", "13", "14", "14", "14", "14", "15", "15", "15", "15", "16", "16", "16", "16", "17", "17", "17", "17", "18", "18", "18", "18", "19", "19", "19", "19", "20", "20", "20", "20", "20", "20", "Bullseye"}
  local SVALUE = {"Single", "Single", "Single", "Single", "Single", "Single", "Single", "Single", "Single", "Single", "Double", "Double", "Double", "Double", "Double", "Double", "Triple", "Triple", "Triple"}
  
  -- generate the darts
  sdarts = {}
  
  for i, snumbers in ipairs (SNUMBERS) do
    for j, svalue in ipairs (SVALUE) do
      table.insert (sdarts, svalue .. " " .. snumbers)
    end -- for each number
  end -- for each value
  
  -- shuffle it
  require "commas"
  shuffle (sdarts)
  

Send ("emote throws a dart at a dart board. " .. table.remove (sdarts))


Thank you.
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #1 on Sun 31 Aug 2014 05:22 PM (UTC)
Message
Simplest solution is to add a specific if for bullseye and print the message you want. Would probably be a LOT cleaner to convert that to a case structure instead of having so many duplicate strings in your tables.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Shady Stranger   USA  (45 posts)  Bio
Date Reply #2 on Wed 10 Sep 2014 12:07 AM (UTC)
Message
I am unfamiliar with case structures. I tried searching for an example but I didn't have any luck. As far as creating an if statement for Bullseyes, I tried the following but then it always hits bullseye.

<aliases>
  <alias
   match="throw dart"
   enabled="y"
   group="darts"
   send_to="12"
   sequence="100"
  >
  <send>
  -- dart names
  local SNUMBERS = {"1", "1", "1", "1", "2", "2", "2", "2", "3", "3", "3", "3", "4", "4", "4", "4", "5", "5", "5", "5", "6", "6", "6", "6", "7", "7", "7", "7", "8", "8", "8", "8", "9", "9", "9", "9", "10", "10", "10", "10", "11", "11", "11", "11", "12", "12", "12", "12", "13", "13", "13", "13", "14", "14", "14", "14", "15", "15", "15", "15", "16", "16", "16", "16", "17", "17", "17", "17", "18", "18", "18", "18", "19", "19", "19", "19", "20", "20", "20", "20", "20", "20", "Bullseye", "Bullseye", "Bullseye"}
  local SVALUE = {"Single", "Single", "Single", "Single", "Single", "Single", "Single", "Single", "Single", "Single", "Double", "Double", "Double", "Double", "Double", "Double", "Triple", "Triple", "Triple"}
  
  -- generate the darts
  sdarts = {}
  
  for i, snumbers in ipairs (SNUMBERS) do
    for j, svalue in ipairs (SVALUE) do
      table.insert (sdarts, svalue .. " " .. snumbers)
    end -- for each number
  end -- for each value
  
  -- shuffle it
  require "commas"
  shuffle (sdarts)

if snumbers == Bullseye then

    Send (" ")
    Send ("emote throws a dart at a dartboard...Bullseye")

else
  
    Send ("emote throws a dart at a dartboard. " .. table.remove (sdarts))

end -- if bullseye</send>
  </alias>
</aliases>
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #3 on Wed 10 Sep 2014 01:45 AM (UTC)

Amended on Wed 10 Sep 2014 01:49 AM (UTC) by Meerclar

Message
Ok, presuming a standard board arrangement, you have 103 possible results from a dart toss. 3 singles, a double and a triple for each number, outer bullseye, inner bullseye and miss. A case structure for that could look something like:


random (120)
case 1|2|3:
send (message for single 1)
case 4|5|6:
send (message for single 2)
case 7|8|9:
send (message for single 3)
case 25:
send (message for double 4)
case 44:
send (message for triple 8)
case 60:
send (message for outer bullseye)
default:
send (message for miss)


Add more cases and messages as needed, will probably need some tweaking for lua and might even work better as a plugin than a trigger since you'd need very little editing once you get everything established.

Also, since you're checking strings, try putting bullseye in quotes in your if check.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,684 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.