Trouble with a script

Posted by Dawastedpanda on Wed 01 Apr 2020 09:04 PM — 3 posts, 13,448 views.

#0
I am hoping to have this plugin track my KiLevel. The problem is that the mud has a prompt with commas in it.
(LifeForce:<86> Ki:<16,050>)



<triggers>
<trigger enabled="n" 
match="*(LifeForce:<*> Ki:<*>)*" 
group="prompt" 
ignore_case="y" 
script="trackKiLevel" 
sequence="100"/>
</triggers>

<!-- Aliases to set the alert level. -->

<aliases>
<alias enabled="y"
match="firstAlert *"
ignore_case="y" 
script="setFirstWarning"  
sequence="100"/>
</aliases>

<script>
<![CDATA[

require "tprint"
firstWarning = 0
currentKiLevel = 0

function setFirstWarning(name, list, args)
	firstWarning = args[1] + firstWarning -- sets the level to a number
	ColourNote("yellow","", "First Alert set to: ","cyan", "", firstWarning)
	EnableTriggerGroup("prompt", true)
end -- function

function trackKiLevel(name, list, args)
	currentKiLevel = tonumber(args[3]) + currentKiLevel
	ColourNote("yellow","", "Current Ki Level: ","cyan", "", currentKiLevel)
	if currentKiLevel < firstWarning then
		ColourNote("yellow","","WARNING! YOUR KI HAS DROPPED BELOW","","cyan", firstWarning)
	end -- if
end -- function
]]>
</script>




The error I get with it is:

Run-time error
Plugin: KiTracker (called from world: DB-Infinity)
Function/Sub: trackKiLevel called by trigger
Reason: processing trigger ""
[string "Plugin"]:164: attempt to perform arithmetic on a nil value
stack traceback:
        [string "Plugin"]:164: in function <[string "Plugin"]:163>
Error context in script:
 160 :  EnableTriggerGroup("prompt", true)
 161 : end -- function
 162 : 
 163 : function trackKiLevel(name, list, args)
 164*:  currentKiLevel = tonumber(args[3]) + currentKiLevel
 165 :  ColourNote("yellow","", "Current Ki Level: ","cyan", "", currentKiLevel)
 166 :  if currentKiLevel < firstWarning then
 167 :   ColourNote("yellow","","WARNING! YOUR KI HAS DROPPED BELOW","","cyan", firstWarning)
 168 :  end -- if
Amended on Wed 01 Apr 2020 09:14 PM by Dawastedpanda
Australia Forum Administrator #1
You will need to get the comma out of that number (16,050).

For example:


  kilevel = string.gsub (args [3], ",", "")
  currentKiLevel = tonumber(kilevel) + currentKiLevel
#2
Nick Gammon said:

You will need to get the comma out of that number (16,050).

For example:


  kilevel = string.gsub (args [3], ",", "")
  currentKiLevel = tonumber(kilevel) + currentKiLevel



Thank you, this worked. I was doing gsub wrong. Appreciate the quick response.