Table question

Posted by Shady Stranger on Sun 31 Aug 2014 01:49 PM — 4 posts, 18,660 views.

USA #0
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.
Amended on Sun 31 Aug 2014 01:52 PM by Shady Stranger
USA #1
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.
USA #2
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>
USA #3
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.