| Message |
OK, well let's clean up the code a bit. When you see lots of "if" statements you can usually do things in a neater way:
<triggers>
<trigger
enabled="y"
match="Your ship fires (\w+) (.+) at (.+)\, and (\w+) land"
regexp="y"
send_to="12"
sequence="110"
>
<send>
local words_to_numbers = {
zero = 0,
one = 1,
two = 2,
three = 3,
four = 4,
five = 5,
six = 6,
seven = 7,
eight = 8,
nine = 9,
ten = 10
}
local var_name = {
["heavy-ballista rounds"] = {
weapon_shot = "ship_hballista_shot",
weapon_hit = "ship_hballista_shot"
},
["light-ballista rounds"] = {
weapon_shot = "ship_lballista_shot",
weapon_hit = "ship_lballista_shot"
},
["fire-launcher rounds"] = {
weapon_shot = "ship_firelauncher_shot",
weapon_hit = "ship_firelauncher_hit"
},
["heavy-cannon rounds"] = {
weapon_shot = "ship_hcannon_shot",
weapon_hit = "ship_hcannon_hit"
},
["medium-cannon rounds"] = {
weapon_shot = "ship_mcannon_shot",
weapon_hit = "ship_mcannon_hit"
},
["light-cannon rounds"] = {
weapon_shot = "ship_lcannon_shot",
weapon_hit = "ship_lcannon_hit"
},
}
local howmany = assert (words_to_numbers ["%1"], "Bad number fired: %1")
local hits = assert (words_to_numbers ["%4"], "Bad number hit: %4")
local t = assert (var_name ["%2"], "No match for: %2")
SetVariable (t.weapon_hit, tonumber (GetVariable (t.weapon_hit)) + hits)
SetVariable (t.weapon_shot, tonumber (GetVariable (t.weapon_shot)) + howmany)
</send>
</trigger>
</triggers>
The above uses a table-lookup to convert words to numbers, and another one to work out which variable to set. Running that on your test line of:
BOOM! Your ship fires ten basic-cannon rounds at Exposed Plague, and six land.
I get this:
Run-time error
World: SmaugFUSS
Immediate execution
[string "Trigger: "]:49: No match for: basic-cannon rounds
stack traceback:
[C]: in function 'assert'
[string "Trigger: "]:49: in main chunk
So there you are. You didn't allow for "basic-cannon rounds".
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|