[Home] [Downloads] [Search] [Help/forum]

Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  OnPluginMXPcloseTag may have a wrong intention of its use

OnPluginMXPcloseTag may have a wrong intention of its use

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

Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Fri 11 Jun 2010 06:20 PM (UTC)

Amended on Fri 11 Jun 2010 06:27 PM (UTC) by Maxhrk

Here my function that i use for my testing purpose before i actually use it for something else like checking prompt, etc.

however, i noticed during testing that it has unexpected result that contrast what has said in the document about what OnPluginMXPcloseTag will give in its variable.

function within my plugin:

function  OnPluginMXPcloseTag(name, text)
	local name = name
	local text = text
	Note("NAME:" .. tostring(name) .. "TEXT:".. tostring(text))
	if name == "PROMPT" then
		confirm = string.find(text, "^(%d+)h, (%d+)m, (%d+)e, (%d+)w (c?e?x?k?d?b?)-$")
		if confirm then
			Note("I got you!")

with that mind, i should have got the prompt line in text variable like this:

<PROMPT>3310h, 2605m, 14400e, 14400w exk-</PROMPT>

however, the result differs from my expectation when it show the variables in name and text content:

NAME:prompt,3310h, 2605m, 14400e, 14400w exk-TEXT:nil

So, I assumed there may be a bug on your hand, Nick.
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] bio
Date Reply #1 on Fri 11 Jun 2010 08:23 PM (UTC)
Actually, no, its working as expected. Its intended to ID tags like, say:

<smudge amount="234">

Where Name = 'smudge' and Text = 'everything else', in this case 'amount="234"'. The only "bug" per say might be that it would have been easier to work with this if an attempt had been made by the function to generate a table or any attributes + values that "appear" to be in there. Just to make things less annoying, instead of forcing you to parse all the stuff after the name yourself, in an attempt to figure out what the heck it all is. But, that is more of an "ease of use" issue, than a bug, per say.
[Go to top] top

Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Reply #2 on Fri 11 Jun 2010 09:17 PM (UTC)
i think you are probably thinking OnPluginMXPopenTag but not the closeTag. Here what the document has to say about OnPluginMXPcloseTag

MXP end tag

This routine is called when an "end" tag is parsed (successfully). For example, "</send>".

Inside a plugin: OnPluginMXPcloseTag

Some tags, marked as EMPTY, do not have end tags.

The arguments are:

1. Tag name, eg. "send"
2. Value of "&text;" variable. In other words, everything that appeared between the start tag and the end tag. This is limited to 1000 characters maximum.

For example, if you had:

<send>eat newspaper</send>

The value of &text; would be "eat newspaper".

function OnMXPEndTag (name, text)
  AppendToNotepad ("MXP", "Closing tag: " .. name .. "\n")
  AppendToNotepad ("MXP", "Text: " .. text .. "\n")
end -- function

hence, what i am expecting is "100h, 100m, 100w, 100e" in the text in OnPluginMXPcloseTag, not OnPluginMXPopenTag.
[Go to top] top

Posted by Nick Gammon   Australia  (23,003 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 11 Jun 2010 09:28 PM (UTC)
The documentation is wrong, or at least, misleading.

See this: http://www.gammon.com.au/forum/?id=9669

It is correct if you have the "close tag" callback in the main world script. In a plugin, it lumps together the name and text into a single argument.

So you need to break up the first argument at the first comma (in case there are more than one comma). Before the comma is the name of the tag, after the comment is the "tag contents".

You can see it here in the code (around line 192):


Notice how the tag name and tag contents are sent separated by a comma.

There was some reason I did it this way, I think laziness in trying to make a whole heap of helper functions for plugins to handle all sorts of different argument patterns. I'll fix up the documentation.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Reply #4 on Fri 11 Jun 2010 10:19 PM (UTC)
ok, thank you very much for answering the question that bothers me. Now, I can fix my code. heh.
[Go to top] 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.


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

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]