Plug-in not capturing values properly

Posted by Aidyn.Hartfire on Wed 27 May 2009 03:42 PM — 7 posts, 28,314 views.

USA #0
As the title implies, I am having a bit of trouble getting a plug-in capturing numerical values like it should. All of the triggers seem to be working perfectly, and when tested offline each mechanism seems to work. However, in-game there seems to be some sort of each. The code below is the specific portion which should capture the numerical values, but doesn't. I'll explain what each is suppose to do in further detail if necessary.




  <trigger
   expand_variables="y"
   group="Forging"
   ignore_case="y"
   match="Damage: *  Precision: *  Speed: *"
   send_to="12"
   sequence="100"
  >
  <send>if %1 &lt; @min_damage then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
elseif %2 &lt; @min_precision then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
elseif %3 &lt; @min_speed then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
end -- if</send>
  </trigger>
  <trigger
   expand_variables="y"
   group="Forging"
   ignore_case="y"
   match="Physical blunt:          *"
   send_to="12"
   sequence="100"
  >
  <send>if @stat_cut &lt; @min_cut then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
elseif @reforge == on then
   SetVariable ("reforge", "off")
   SetVariable ("next", "on")
elseif %1 &lt; @min_blunt then
   SetVariable ("reforge", "on")
   SetVAriable ("next", "on")
   Execute ("reforge")
end -- if</send>
  </trigger>
  <trigger
   expand_variables="y"
   group="Forging"
   ignore_case="y"
   match="Physical cutting:          *"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable ("stat_cut", "%1")</send>
  </trigger>
</triggers>
USA #1
Additional quick question, could it be that the plug-in needs the "to number" function coded in? I apologize if this seems silly, but I haven't coded in forever, so if someone could be patient enough to answer that would be great.
USA #2
Anytime you have a string which is supposed to be a number, you probably want to call "tonumber" on it to do the conversion.

Also, when reporting a problem with a plugin, it's generally useful to give an example of what doesn't work: show what you expected to happen, and then show what actually happens. This helps us get information needed to figure out what's going on.
Australia Forum Administrator #3
As David says, it helps to state what sort of "trouble" you are having. Is there an error message? If so, what is it? Something like "attempting to perform arithmetic on a nil value" would tend to narrow it down a bit.

Also some test cases. If the plugin works some of the time, a comparison of the conditions which work, and those that don't, would help.

One idea springs to mind is that the numbers you are extracting may have commas in them. So for example, if the plugin works if the damage is 987, but not when it is 1,012 then the comma after the "1" is probably the cause.

You can use string.gsub to remove commas.
USA #4
Right, sorry for being so vague. I was a bit rushed earlier. Anyhow, the plug-in is forging things in the game Lusternia. Essentially, there should not be any number which has more than three digits, as armor with a rating of 90 or above is ideal with anything in the 100s perfect. I've never heard of anyone having something greater than 110 or so. Weapons are slightly different, but I don't think they would exceed 300. If that.

The two primary triggers would be:


  <trigger
   expand_variables="y"
   group="Forging"
   ignore_case="y"
   match="Damage: *  Precision: *  Speed: *"
   send_to="12"
   sequence="100"
  >



Which should activate on a line such as:


Damage: 150  Precision: 170  Speed: 200



Then do the following:


<send>if %1 &lt; @min_damage then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
elseif %2 &lt; @min_precision then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
elseif %3 &lt; @min_speed then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
end -- if



Where if the first number is less than the number specified in the variable min_damage then it should break the item down into it's key components and remake the item. The same goes for all three numbers. All three have to meet or exceed the minimum set for it.

Now, every other component of the plug-in works flawlessly, except for capturing the numbers properly. Instead it always reforges, which is a pain because then I cannot leave it unattended. I think I'll give a shot to converting the strings to numbers and see if that works.
Australia Forum Administrator #5
In this particular case, using tonumber should not be necessary. I would put in debugging displays to see what is happening. For example, maybe something else is reforging. ;)

Something like this:


if %1 &lt; @min_damage then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
   print ("reforging because damage (%1) less than minimum (@min_damage)")
elseif %2 &lt; @min_precision then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
   print ("reforging because precision (%2) less than minimum (@min_precision)")
elseif %3 &lt; @min_speed then
   SetVariable ("reforge", "on")
   SetVariable ("next", "on")
   Execute ("reforge")
   print ("reforging because speed (%3) less than minimum (@min_speed)")
end -- if

USA #6
It seems to be working properly after having used tonumber. Who knows. If I go over the log file in the morning and find that it wasn't executing properly then I'll make the change you suggested, Nick.