When using addxml.trigger no error is produced, at creation, if the name is nil.

Posted by Mendaloth on Thu 24 Nov 2011 01:40 PM — 7 posts, 26,833 views.

#0
See the following code:

	trigger_name = nil
	addxml.trigger {  match = "MATCH ONE", 
							regexp = false,
							sequence = 3,
							enabled = true,
							omit_from_output = true,
							name = trigger_name,
							script = "Process_Noble_Message"
						  }


This produces no error when the trigger is added, but always produces "Trigger function "Process_Noble_Message" not found or had a previous error." when the trigger is matched. Since there is no previous error, I was confused as to why it did not think there was a function called "Process_Noble_Message" when I knew there was.

Obviously it is easy notice the error in this simple example above, but in my program the name was set using a variable that did not exist.

I would suggest addxml.trigger display this as an error, as it does with other errors.
Australia Forum Administrator #1
Is your concern that an error is not raised when it should be, or that there should be no error because the function Process_Noble_Message exists?

The addxml module uses the ImportXML function to import XML (after converting a table into XML).

ImportXML checks for syntactic correctness of the XML, and that various things are in range. However it doesn't check all script functions exist. In the case of loading a world file (or plugin) these checks are a later step, in case a trigger is loaded physically earlier in the file than the script part.

What you can do is check yourself. There is a selector for GetTriggerInfo that tells you if the script is valid. For this to work you would have to give the trigger a name, eg.


script_ok = GetTriggerInfo ("foo", 34)   --> false


To check "manually" you can load a filter from the file Example_Filters.lua and paste that into the box that appear when you hit "..." in the triggers list configuration dialog. (Just part of that file, read the comments).

Then hit the "Filter by" checkbox and you will see a list of things you can filter by, including "Script name not found". The list of triggers is then reduced to those that have no matching script.
#2
Sorry, should have been clearer. The error in this case is that the name of the trigger is nil.

It does not raise this as an error when you use addxml to create the trigger (In my case I do it on plugin install).

Instead it produces an error when it matches text. The error message does not accurately describe the error in my mind. It says "Trigger function "Process_Noble_Message" not found or had a previous error." The "Process_Noble_Message" does exist, and when it says "or had a previous error" I assume if it had a previous error it would actually say "Hey this is an error."
Australia Forum Administrator #3
Quote:

The error in this case is that the name of the trigger is nil.


That's not an error. Trigger names can be nil. They are auto-assigned names in that case.

Quote:

It says "Trigger function "Process_Noble_Message" not found or had a previous error."


It is complaining that the function either does not exist, or exists but raised a (runtime) error previously and is now flagged as "no good".

Template:version
Please help us by advising the version of MUSHclient you are using. Use the Help menu -> About MUSHclient.
#4
I am using version 4.77.

Take the clean plugin below.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, August 06, 2008, 1:13 PM -->
<!-- MuClient version 4.35 -->

<!-- Plugin "Consider_info" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Error_Tester"
   author="Mendaloth"
   id="2a5cbb1cd55bcaf665e2a23d"
   language="Lua"
   purpose="Tests Errors"
   date_written="2008-10-15 07:35"
   requires="4.30"
   version="1.0"
   save_state="y"
   >
<description trim="y">
<![CDATA[

]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>

 
  
</triggers>

<aliases>
  
</aliases>



<!--  Script  -->


<script>
<![CDATA[

require "tprint"
require "serialize"


function Process_Noble_Message(name, line, wildcards, styles)
	Note("It worked")
end



function OnPluginInstall ()	
	require "addxml"
	
	local fake_name = nil
	
	addxml.trigger {  match = "MATCH THIS 12344", 
							regexp = false,
							sequence = 3,
							enabled = true,
							omit_from_output = true,
							name = fake_name,
							send_to = 12,
							script = "Process_Noble_Message"
						  }
	
	Note("Got here")
		
	
end


]]>
</script>

</muclient>


On a fresh install of above plugin no errors are produced. If you run it for the first time, or right after it was removed and re-added, the function "Process_Noble_Message" should never be called and never says it has had an error.

When it matches "MATCH THIS 12344" it then produces an error saying "Trigger function "Process_Noble_Message" not found or had a previous error."

Not a huge deal. I've fixed it in my plugin, just thought technically it was a bug, perhaps not....
Amended on Thu 24 Nov 2011 09:03 PM by Mendaloth
Australia Forum Administrator #5
Hmmm, there is a sort-of a bug there. Notice this:

http://www.gammon.com.au/forum/?id=7336

It seems this is a known issue, and the addxml plugin works around this by doing this:


function trigger (t)
  GeneralAdd (t, "trigger", "triggers")
  -- force script entry-point resolution
  if t.name and t.script then
    SetTriggerOption (t.name, "script", t.script)
  end -- if trigger has a name, and a script name
end -- addxml.trigger


However to do a SetTriggerOption it has to know the name of the trigger, so if you have an unnamed trigger it can't do that.

So your workaround is to give the triggers names, even if you just generate one randomly, or use GetUniqueNumber or GetUniqueID.

Mind you, generally you shouldn't need to add triggers on-the-fly like that.
#6
Nick Gammon said:

Hmmm, there is a sort-of a bug there. Notice this:

http://www.gammon.com.au/forum/?id=7336

It seems this is a known issue, and the addxml plugin works around this by doing this:


function trigger (t)
  GeneralAdd (t, "trigger", "triggers")
  -- force script entry-point resolution
  if t.name and t.script then
    SetTriggerOption (t.name, "script", t.script)
  end -- if trigger has a name, and a script name
end -- addxml.trigger


However to do a SetTriggerOption it has to know the name of the trigger, so if you have an unnamed trigger it can't do that.

So your workaround is to give the triggers names, even if you just generate one randomly, or use GetUniqueNumber or GetUniqueID.

Mind you, generally you shouldn't need to add triggers on-the-fly like that.


Yeah in this case I had meant to create a name for the trigger, but there was an error in the way I did it which caused the variable to be nil. Just took me a while to figure out that was the error, hence the bug report.

Thanks for the prompt response and patience as I tried to explain it :)