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 ➜ Tips and tricks ➜ Match on prompt lines with no newline

Match on prompt lines with no newline

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


Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Thu 24 Oct 2002 03:09 AM (UTC)

Amended on Mon 03 Feb 2003 10:46 PM (UTC) by Nick Gammon

Message
Every now and again someone wants to make a trigger that matches on the prompt line, which MUSHclient doesn't do directly, because its trigger matching is deferred until a newline is received.

This can be annoying if you want to make triggers to answer the initial questions in a MUD (eg. "What race do you want ..."), or to have a prompt line immediately update a hit point status line.

There is a way, using the fairly recent GetLineInfo script function. Basically the method is to use a timer, the timer calls a script, the script gets the very last line in the output buffer, checks to see if it has a newline, and if not, runs a regular expression on it to see if it matches whatever you are trying to match on.

Depending on how quickly you want the information to be processed you might make a 1-second timer (of course, this would have a bit of overhead), or maybe a 5 or 10-second timer would do.

An example of doing this is below, it updates the status line based on a Dawn Of Time prompt line. To use it, just make a simple timer that calls "CheckPrompt" script every few seconds.




sub CheckPrompt (sName)
Dim regEx, Matches, Match, sLine, iNumber
Dim hp, m, xp, mv

'
'  Find line number of last line in buffer
'
  iNumber = world.GetLinesInBufferCount

' ignore lines with a newline at the end

  if world.GetLineInfo (iNumber, 3) then exit sub

' ignore world.note lines

  if world.GetLineInfo (iNumber, 4) then exit sub

' ignore player input lines

  if world.GetLineInfo (iNumber, 5) then exit sub

'
' So far we have a line that is MUD output (not note or command)
'  and it doesn't have a newline, so it is probably a prompt
'

' get text of line

  sLine = world.GetLineInfo (iNumber, 1)

'
' Make a regular expression to match on a line like this:
'
'  [EW 10:10pm 5/5hp 100/100m 94mv 996xp> 
'  
  Set regEx = New RegExp
  regEx.Pattern = "(\d+)/\d+hp (\d+)/\d+m (\d+)mv (\d+)xp"

'
'  Execute regular expression
'

  Set Matches = regEx.Execute (sLine)

'
'  Exit if no match

'
  if Matches.Count = 0 then  exit sub


  Set Match = Matches.Item (0)

  Set regEx = Nothing
  Set Matches = Nothing

'
'  Pull out the sub-matches (individual numbers)
'

  hp = CInt (Match.SubMatches (0))
  m = CInt (Match.SubMatches (1))
  mv = CInt (Match.SubMatches (2))
  xp = CInt (Match.SubMatches (3))

  Set Match = Nothing

'
'  Update the status line
'

  world.SetStatus "hp = " & hp & " m = " & m &  _
                  " mv = " & mv & " xp = " & xp

end sub

- Nick Gammon

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

Posted by Togras   (5 posts)  Bio
Date Reply #1 on Sat 30 Nov 2002 03:44 PM (UTC)
Message
There's an even SIMPLER way...

Just put *'s on either end of your trigger.

Done.
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #2 on Sat 30 Nov 2002 07:01 PM (UTC)
Message
Sorry Togras, but that doesn't in fact work, since the line is not processed until a newline happens. I.e.>

Enter your password: _

can't be matched, using '*Enter your pasword:*' because until you actually type a password and hit enter, the client won't process that line through triggers. Nicks suggestion on the other hand takes advantage of the fact that the line is being displayed, even though the client assumes it is still incomplete. Thus you can 'read' the line through scripting and react to it, even though triggers won't.
Top

Posted by Plazgoth   USA  (10 posts)  Bio
Date Reply #3 on Mon 03 Feb 2003 05:55 PM (UTC)
Message
In the example above where do you define 'mv'. Also is there a way to gag the promp from the output?
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 03 Feb 2003 10:54 PM (UTC)
Message
I accidentally omitted "mv" from the "dim" line - I have edited the post to add it.

You could gag the prompts by omitting them from output, however the gagging only takes effect when the newline is received - which is the problem that this whole topic addresses.

It won't be too bad - it means the prompt will appear - then the script kicks in a second later and updates the status line, and then when more output arrives from the MUD the prompt line is omitted, so you only ever see the bottom one. This is good in a way, as the most recent one is really the only relevant one.

You can work around that on some MUDs which let you customise the prompt, by making your own prompt with a newline in it, that way the prompt is omitted immediately (and there is no need for this script in the first place).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


18,792 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.