Not understanding what's wrong with my script

Posted by Dawastedpanda on Tue 10 Mar 2020 09:35 PM — 6 posts, 21,299 views.

#0

168 : function toTarget(name, line, args)
169 : if args[1] ~= nil and args[1] ~= "" then
170 : mobTarget = args[1]
171*: elseif mobTarget = "none" then
172 : triggerOff()
173 : ColourNote ("yellow", "", "Sensing Target Cleared.")
174 : return
175 : end
Amended on Thu 12 Mar 2020 03:48 AM by Nick Gammon
#1

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, March 08, 2020, 1:40 PM -->
<!-- MuClient version 4.94 -->

<muclient>
<plugin
   name="AutoSenseV4"
   author="Kaiza"
   id="6f28bac9aa18955b674c0d43"
   language="Lua"
   purpose="Automatically Sense Mobs"
   save_state="y"
   date_written="2020-03-10 13:39:17"
   requires="4.94"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>


<!--  Triggers  -->

<triggers>
<trigger name= "senseTarget" match= "You concentrate and sense their ki *" group= "sense" script= "trackTarget"   enabled= "y" regexp= "y" sequence= "100"/>
<trigger name= "atTarget"    match= "You're already in the same room!!"    group= "sense" script= "triggerOff" enabled= "y" regexp= "y" sequence= "100"/>
<trigger name= "cantSense"   match= "That mob does not exist, cannot *"    group= "sense" script= "triggerOff" enabled= "y" regexp= "y" sequence= "100"/>
</triggers>

<aliases>
<alias name= "trackTarget" match= "track *"  script= "toTarget" enabled= "y" regexp= "y" send_to="1" sequence= "100"/>
</aliases>
<script>
<![CDATA[

local mobTarget = ""

function triggerOn()
    EnableTriggerGroup ("sense", true)
end
function triggerOff()
    ColourNote ("yellow", "", "Sensing disabled.")
    EnableTriggerGroup ("sense", false)
end

function trackTarget()
    triggerOn()
    Send("sense ".. mobTarget)
end

function toTarget(name, line, args)
  if args[1] ~= nil and args[1] ~= "" then -- entered one mob to track
	mobTarget = args[1]
  elseif mobTarget = "none" then
    triggerOff()   -- disables the trigger if none is entered.
	ColourNote ("yellow", "", "Sensing Target Cleared.")
    return
  end
  trackTarget()
end
--[[ 
  <alias match="^track (.*?)?$" script="toTarget" enabled="y" ignore_case="y" regexp="y" sequence="100" />
  ]]--

]]>
</script>
</muclient>




That is my entire script. I want to be able to type track (mob) and it will automatically begin sensing the mob
Amended on Thu 12 Mar 2020 03:48 AM by Nick Gammon
USA Global Moderator #2
Next time please include the error message as well. But I can say already that
elseif mobTarget = "none" then

needs to have == not =
Amended on Wed 11 Mar 2020 04:00 AM by Fiendish
#3
Thank you, that fixed the problem I was having. It lead me to a new problem though.

When I type track (mobname) In game, it is not picking up the wild card and assigning it to mobTarget.

Any idea why?
Australia Forum Administrator #4

<alias name= "trackTarget" match= "track *"  script= "toTarget" enabled= "y" regexp= "y" send_to="1" sequence= "100"/>


First, you have checked "regular expression" but it isn't really a regular expression. (It is, but it matches "track" followed by zero or more spaces, and you haven't assigned that to be a wildcard).

Either get rid of regexp= "y" or make the match text a regular expression, eg.


^track (.*)$


Second, you made "mobTarget" local which means its lifetime is not as long as you would like. Get rid of "local" before mobTarget.

(Actually, that might only apply to how I was testing it. Fix the regular expression first and see what happens).
Amended on Thu 12 Mar 2020 03:59 AM by Nick Gammon
#5
Problem is completely fixed. Thank you. It runs fine now.