Well, the situation is exactly as the error message says. At the time you are trying to deduct TemperDamage from FinalDamage to get the difference, TemperDamage cannot be converted since it is 'a nil value'.
In other words, you never stored a value in that MUSHclient variable, since the GetVariable() call returned nil.
Thus, are you sure you are setting the variable properly beforehand? I am going to do a bit of conjecture now, but I believe you are misunderstanding the wait.regexp() function in how it works and how it should be used. (Disclaimer: I have never used the wait library, as it was written way after I started coding and I never really got the hang of switching to using/learning it.)
Basically, the wait.regexp() will MAKE a new trigger behind the scenes, and from that, call back to your code so it can be run once more. That trigger will quite likely prevent your OTHER trigger from being run. To boot, you are doing your own matching in a loop to see if the word Speed is in the trigger somewhere, where it should not be needed anymore. And eventually, due to the wait the wait library works, you think you have done the entire waiting gig, but end up doing the calculations immediately.
So, once your wait.regexp() matches, you get your values deposited in the line and wildcards variables. Thus, you could simply fill the appropriate variables at that point. So, I'd arrive at something like this for you to put in your Send box...
require "wait"
wait.make (function ()
-- Send the command.
local TemperWeapon = GetVariable("weapon_number")
Send ("wp " .. TemperWeapon)
-- Wait for the line. (Your old trigger is not needed.)
local line, wildcards =
wait.regexp ("^\\s*Damage:\\s+(\\d+)\\s+Precision:\\s+(\\d+)\\s+Speed:\\s+(\\d+)\\s*$")
-- Assign the values according to the captures.
-- These are local to this 'scope' only, so you can't use them elsewhere
-- in your script. If you do want to use them elsewhere, remove the
-- 'local' bits, and they will become available to your entire script,
-- no matter which trigger, alias or timer it would be.
local TemperDamage = wildcards[1]
local TemperPrecision = wildcards[2]
local TemperSpeed = wildcards[3]
-- Do our logic stuff. (I took some liberties here since you had so many
-- variables, some of which you never assigned, so it likely doesn't do
-- exactly what you want. Still, hopefully you can understand how this
-- works now.
local FinalDamage = TemperDamage
local DamageDifference = FinalDamage - TemperDamage
end)
Also, on another note... your wait.regexp() call is called with a string containing the regular expression to trigger on, but you should keep in mind that Lua will do some magic with backslashes (the \ character) itself. (Think of when you want to put a literal newline into a string, one would use a \n, thus the actual text '\n' would need to be written as '\\n' in your code. If you want to send a literal \ to the regexp function, you'll need to double it (and yes, you want that here). Thus, that would become...
wait.regexp ("^\\s*Damage:\\s+(\\d+)\\s+Precision:\\s+(\\d+)\\s+Speed:\\s+(\\d+)\\s*$")
(I already put that 'fix' in the above example.)
Edit: Nick, why the hell is the forum eating my backslashes outside the edit screen once forum codes are activated? Gonna double them up to insane levels now, I suppose. Bear with me Lilija while I fix the post.
Edit: Post should be fixed. Nick, if you fix the forum (I assume it is a bug as no other forum I know does it), please fix this post back? On the other hand, that could explain why Lilija's wait.regexp() missed half its backslashes, so I might be able to remove that part of my post. xD |