Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ When using addxml.trigger no error is produced, at creation, if the name is nil.

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

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Mendaloth   (14 posts)  Bio
Date Thu 24 Nov 2011 01:40 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 24 Nov 2011 07:02 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mendaloth   (14 posts)  Bio
Date Reply #2 on Thu 24 Nov 2011 07:31 PM (UTC)
Message
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."
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 24 Nov 2011 07:46 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mendaloth   (14 posts)  Bio
Date Reply #4 on Thu 24 Nov 2011 09:01 PM (UTC)

Amended on Thu 24 Nov 2011 09:03 PM (UTC) by Mendaloth

Message
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....
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 25 Nov 2011 12:20 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mendaloth   (14 posts)  Bio
Date Reply #6 on Fri 25 Nov 2011 12:44 AM (UTC)
Message
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 :)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


25,201 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.