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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
kyran64
Beginner


Joined: 18 Feb 2008
Posts: 11

PostPosted: Fri Apr 20, 2012 5:13 am   

Multiple lines with a trigger...when you don't know where the linebreak is.
 
Greetings!

So, this is a fairly common question on the forums...I've browsed a number of the Q and A's about this topic and unfortunately..the only one I found that matched my particular dilemma was never solved. And it was from 2004. So hopefully in the past 8 years there may be a new answer Very Happy

My MUD automatically chunks anything over a certain number of characters and splits it up. ..so it is not CMUD that wordwraps the output from the MUD. There are also no options available as a player to turn it off.

So here's the fun part. Combat can easily spill over onto a second or third line depending on the enemy' s name, weapon's name, body part being hit, armour blocking the strike...so on and such forth. So there's no telling at any given point where the break will be which makes it difficult to write scripts to track or respond to combat situations.

Or...more immediately near and dear to me as an alchemist...cutting potion components off of corpses. It's usually just two lines...but sometimes one or three.

Example:
Search corpse
>
After searching the corpse you believe you can tear out or cut off two
thighbones, three nails, and a liver.

or

After searching the corpse you believe you can tear out or cut off a nail,
a kneecap, and a skull.

....most of the parts appear on the second line, but not all, not always, and not always the number of parts available.


The search always ends with with a period and there is never a period anywhere else regardless of how many lines the response may be. Is there perhaps a way for a trigger to to just combine all the lines between when it's activated by the opening phrase and when it hits that specific punctuation?

Combat's not always so clean and consistent...so the same trick wouldn't necessarily work there. BUT...if I could get the corpsecutting part taken care of, that'd be an incredible start :)

Thoughts?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Apr 20, 2012 1:49 pm   
 
Yes.
Code:

#TRIGGER {After searching the corpse} {
  #VAR corpseline %1
  #IF (%match(%1,"*.")) {CODE FOR PARSING THE CORPSECUT} {#T+ corpsecut}
}

#TRIGGER corpsecut {(*)} {
  #VAR corpseline %concat(@corpseline, %1)
  #IF (%match(%1,"*.")) {CODE FOR PARSING THE CORPSECUT;#T- corpsecut}
}

#T- corpsecut

Interpretation: The first trigger catches the "After searching the corpse" line and saves it to the variable @corpseline. Then it checks whether the line ends in a period. If it _does_ end in a period, it parses the line (with whatever code you need to do that). If it _doesn't_ end in a period, it turns on the second trigger.

The second trigger appends the next line to @corpseline. If that line ends in a period, it parses the line and turns itself off. If it doesn't end in a period, it stays active, and repeats the process on the next line.

The third command simply turns the second trigger off, to initialize it.
Reply with quote
kyran64
Beginner


Joined: 18 Feb 2008
Posts: 11

PostPosted: Fri Apr 20, 2012 7:13 pm   
 
Rahab wrote:
Yes.


You, sir, are a genius. And I am twice now in your debt.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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