[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Table question
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Table question

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


Posted by Shady Stranger   USA  (45 posts)  [Biography] 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.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

Posted by Shady Stranger   USA  (45 posts)  [Biography] 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>
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] 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.


2,957 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]