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 ➜ Programming ➜ General ➜ Line number of line that caused a trigger to fire

Line number of line that caused a trigger to fire

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


Posted by Seriley   (42 posts)  Bio
Date Sun 05 Dec 2010 08:02 PM (UTC)
Message
If I need to know the actual line# of a line sent from the Mud that causes a trigger to fire, will it ALWAYS be found if trigger processing uses GetLineInfo(GetLinesInBufferCount()).line?

Is there a better way to get this information while processing a trigger?

Top

Posted by Seriley   (42 posts)  Bio
Date Reply #1 on Sun 05 Dec 2010 08:06 PM (UTC)
Message
Oops. Just found GetLineCount(). Is this always the correct line# when processing a trigger fired by that line?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Sun 05 Dec 2010 11:02 PM (UTC)
Message
See the help for that.


Description

This returns the number of lines received by this world. However, see GetLinesInBufferCount for the number of lines currently in the output buffer, which might be different.


In other words, if you have the output buffer size at 1000 lines, then GetLineCount will be right for the first 1000 lines, then it will discard 100 lines, so after that line 1001 will actually be line 901 in the buffer.

So you really want GetLinesInBufferCount.

However, again, if this trigger (or another one which happened to fire previously) has added a Note to the output buffer, then the Note will be the last line, not the triggered line. Also, lines can wrap, so if you have a 2-line "line" (that is, a line which doesn't have a linefeed inside the wrapping column) then GetLinesInBufferCount would give the second line, not the first one.

But why do you need to get this in the first place? In most cases there is an easier way.

- Nick Gammon

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

Posted by Seriley   (42 posts)  Bio
Date Reply #3 on Mon 06 Dec 2010 03:37 AM (UTC)
Message
I am trying to adapt your (Nick's) Materia Magica mapper to Cities of M'Dhoria (CMD).

CMD doesn't provide a unique way to trigger on the name of a room, but it does provide and easily identifiable exit line AND the ability to retrieve the room name from the prompt.

So I'm doing the following on each prompt
- Store the last prompt line's actual Mud line number
- Store this prompt line's actual Mud line number
- get this line's Buffer line number
- get the room name from the prompt itself

- compute the difference in actual line numbers and subtract it from the buffer line number to get the approximate position in the buffer of the previous prompt. My assumption is that I will land on the original prompt line in the buffer or an earlier line if lines were not sent to output.

- walk forward through the buffer until I find the name line by matching with the name in the subsequent prompt.

- build a description string starting with the next buffer line and proceeding until I find the exit line.

- build the key as is done in the Materia Magica mapper plugin.

I only do this processing if an exit line was in fact encountered between the last and current prompt lines

So far it seems to capture the right information
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 06 Dec 2010 04:42 AM (UTC)
Message
Yes, very cunning.

Well this might help:

Template:function=GetRecentLines GetRecentLines

The documentation for the GetRecentLines script function is available online. It is also in the MUSHclient help file.



That returns lines that arrived from the MUD (not notes or player input). For your purposes that might be better. It is in fact what is used for multi-line matches.

So in that case you probably do want GetLineCount - as that is lines received from the MUD. If you use GetLineCount for the previous prompt, and GetLineCount on the current prompt, that should give you the number of lines received from the MUD itself between prompts. Then just use GetRecentLines (n) where n is that number, and you have a nice array of lines to examine for the room name and description.

That should be pretty reliable then.

- Nick Gammon

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

Posted by Seriley   (42 posts)  Bio
Date Reply #5 on Mon 06 Dec 2010 06:01 AM (UTC)
Message
As always, thanks for your help and prompt replies, Nick!

GetRecentLines looks good.

So far my mapper is doing fine creating rooms, etc. I haven't run across one that hashes to an existing key yet (fingers crossed)
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.


17,923 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.