Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Wed Jul 25, 2007 5:03 am   

Capturing room description to a variable
 
Hi,

I would like to catch the room description to a variable
for further processing, after pressing 'l' for look.
So, I press 'l' and mud outputs something like this:
Code:

You are standing near some fountain. Very big
trees are looming over you, a couple of bushes
grow nearby.
There is one obvious exit: north

Of course room descriptions may differ and may have different length.
Also I can not change the size of columns, so multiple line parsing is involved.
However, the last line is either "There (*) obvious exit:" or
"There (*) obvious exits:"

I tried doing it with #ONINPUT, but how do I catch the lines from the mud then ?

Thanks for your help
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Jul 25, 2007 5:30 am   
 
A multistate trigger will probably work best.

#trig {^{l|look}$} {#t+ capture;#var RoomDesc ""} "" {oninput}
#cond {There {is|are} %w obvious exit{|s}:} {#t- capture}

#trig "capture" {^(*)$} {#additem RoomDesc %1} "" {disable}

What sort of "further processing" are you doing? There might be a better way to do this. And in addition, this'd be a lot simpler if you could turn off server-side word wrapping.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Wed Jul 25, 2007 5:55 am   
 
Fang Xianfu wrote:

What sort of "further processing" are you doing? There might be a better way to do this. And in addition, this'd be a lot simpler if you could turn off server-side word wrapping.


I have auto wrapping turned off on the mud.
Further processing - I would like to extract each word from the string and use that word as an argument for other commands to the mud, for example:
"There is a hole in the wall near a couple of bushes" - I would like to extract each word, so I could then use some of them like {hole | wall | bushes } in a #forall loop
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Wed Jul 25, 2007 2:02 pm   
 
list=%subchar(@description," ","|")

#Forall @list {probe %i}
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Wed Jul 25, 2007 2:36 pm   
 
Fang Xianfu wrote:
And in addition, this'd be a lot simpler if you could turn off server-side word wrapping.


I have auto wrapping off on the mud. How can this be made simpler ?

Regards,
uff
Reply with quote
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Wed Jul 25, 2007 2:43 pm   
 
Arminas wrote:
list=%subchar(@description," ","|")

#Forall @list {probe %i}


Yes, it would be nice also to remove things like dots and commas from the end of every word
But I guess it is easy with #forall and some kind of #if
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Jul 25, 2007 3:09 pm   
 
It can be made easier because all the text of the room description will be one line. You can do something like this:

#trig {^{l|look}$} {} "" {oninput}
#cond {^(*)$} {list=%subchar(%1," .,","|"}

Because the line after a look will always be the description. You could make it a bit more robust by doing something like

#trig {^{l|look}$} {} "" {oninput}
#cond {^(*)$} {list=%1}
#cond {There {is|are} %w obvious exit{|s}:} {list=%subchar(@list," .,","|"} {within|param=1}

I assume you're just going to do #forall @list {#if !%ismember(%i,@ListofNonNouns) {probe %i}}

where @ListofNonNouns is something like the|a|you|near|couple|of|looming|over|nearby etc etc. You'll never make a complete list, but it'll cut down the spam some.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Wed Jul 25, 2007 6:39 pm   
 
Fang Xianfu wrote:
A multistate trigger will probably work best.

#trig {^{l|look}$} {#t+ capture;#var RoomDesc ""} "" {oninput}
#cond {There {is|are} %w obvious exit{|s}:} {#t- capture}

#trig "capture" {^(*)$} {#additem RoomDesc %1} "" {disable}


Thank you, this almost works for me in this way:
Code:

[^{l|look}$-> #t+ capture;#var RoomDesc ""]
[^(*)$-> #additem RoomDesc l]

This old warehouse has seen its glory days long time ago.
[^(*)$-> #additem RoomDesc This old warehouse has seen its glory days long time ago.]
It is rather empty except for two crates and a pile of
[^(*)$-> #additem RoomDesc It is rather empty except for two crates and a pile of]
sand which is dumped in a corner.
[^(*)$-> #additem RoomDesc sand which is dumped in a corner.]
There is one obvious exit: east.
[There {is|are} %w obvious exit{|s}:-> #t- capture]


but this is what is put in the list variable
Code:

l|This|It|sand


Only the first word from each line.

Unfortunately this:
#trig {^{l|look}$} {} "" {oninput}
#cond {^(*)$} {list=%1}
#cond {There {is|are} %w obvious exit{|s}:} {list=%subchar(@list," .,","|"} {within|param=1}

takes out only the first line. It seems the mud still autowraps the lines.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Wed Jul 25, 2007 7:12 pm   
 
Fang is thinking in Cmud terms. You need to put quotes around the %1.

#trig "capture" {^(*)$} {#additem RoomDesc "%1"} "" {disable}

Should do the trick.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Wed Jul 25, 2007 7:22 pm   
 
Arminas wrote:
Fang is thinking in Cmud terms. You need to put quotes around the %1.

#trig "capture" {^(*)$} {#additem RoomDesc "%1"} "" {disable}

Should do the trick.


Thanks very much. This works !
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Jul 25, 2007 7:24 pm   
 
Also, if you're using the %subchar suggestion, you might find that this creates a string list with four items where each item is a line, but the spaces have been replaced with |. You might have to do something like #forall %subchar("%1"," .,","|") {#additem RoomDesc %i} instead.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Wed Jul 25, 2007 8:44 pm   
 
Thanks very much for the help, however there is one small thing.
When I first send 'l' command to the mud everything is ok, variable is filled with room description.
But after that it does not work, I have to type in for example a "#var" command or "#echo @RoomDesc" command.
Afterwards 'l' command works once and then again it does not.
I use these triggers:

#trig {^{l|look}$} {#t+ capture;#var RoomDesc ""} "" {oninput}
#cond {There {is|are} %w obvious exit{|s}:} {#t- capture}

#trig "capture" {^(*)$} %subchar( "%1", " .,:0123456789", "|") {#additem RoomDesc %i}
"" {disable}
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Jul 25, 2007 8:50 pm   
 
If you didn't make a typo there, your capture trigger is wrong. There's a "{#forall " missing before the %subchar.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
uff
Newbie


Joined: 24 Jul 2007
Posts: 8

PostPosted: Thu Jul 26, 2007 6:50 am   
 
Fang Xianfu wrote:
If you didn't make a typo there, your capture trigger is wrong. There's a "{#forall " missing before the %subchar.


Yes, I made a typo, I have the #forall before the %subchar

^(*)$ -> #forall %subchar( "%1", " .,:0123456789", "|") {#additem RoomDesc %i} "" {disable}

But still it only works once and then I have to write #var or something else to make it work again
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net