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
aedron
Beginner


Joined: 29 Nov 2008
Posts: 20

PostPosted: Fri Dec 05, 2008 9:41 am   

wildcards and variables
 
Is there a way to set a variable from a reflex that has select words in it? For example..

You howl in agony from getting {struck|bashed|pounded|smashed|crushed} in the bowels.$

What I want the value to do is set a variable to whatever the list of words can be. The value would be something like

damagetype=(one of the verbs from the reflex would go here)

Let's say the mud showed

You howl in agony from getting smashed in the bowels.

I'd want the variable damagetype set as smashed. Is there a way to do this?

Edit: also if this is possible, could I use this variable in an #if statement? ex. #if @damagetype=(whatever the variable was set as) {blah}
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Fri Dec 05, 2008 10:26 am   
 
Put () around the {}. Anything with () around it is put into one of the %1-%99 variables.

You can then do #if (%1="struck") {stuff} or whatever.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
aedron
Beginner


Joined: 29 Nov 2008
Posts: 20

PostPosted: Sun Dec 07, 2008 9:36 pm   
 
Since () places things as %1, could I use (%w %w) in the case of if, sometimes an attack will target my head, torso, right arm, left arm, etc. and I need to set the variable to the limb which was hit.

^Turning quickly, %w kicks you in the (%w) with {his|her} {right|left} foot.$

Sometimes the %1 in this reflex will be either head, chest, right arm, left arm. Will this value still work?

#if %1="head" {#var damagedlimb %1}
#if %1="chest" {#var damagedlimb %1}
#if %1="right arm" {#var damagedlimb %1}
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sun Dec 07, 2008 10:00 pm   
 
Personally I'd use Regex and (.+) but I'm sure there are more sophisticated ways for writing it (like making one word "permanent" but not the other one).

Code:


^Turning quickly, \w+ kicks you in the (.+) with (?:his|her) (?:right|left) foot\.$



If you want to use Zscript for the trigger, you can use (*) however I'm taking a guess it'd at least little bit slower than the one above.

Hope this helps.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Dec 07, 2008 10:34 pm   
 
Personally, you're better off putting things in variables and triggering off that. For instance:

#VAR targetlimbs {head|torso|right arm|left arm|right hand|left hand|right foot|left foot|right leg|right leg}

#TRIGGER {^Turning quickly, %w kicks you in the ({@targetlimbs}) with {his|her} {right|left} foot.$} {#VAR damagedlimb %1}

Makes things SO much easier, and it'll always put the right limb into the damagedlimb variable. You don't even need all those "ifs" in the value.

Charneus
Reply with quote
aedron
Beginner


Joined: 29 Nov 2008
Posts: 20

PostPosted: Sun Dec 07, 2008 11:06 pm   
 
Hrm what about if I'm trying to set the limb which was broken to a variable?

^%w applies intensive pressure. You howl as your ({@targetlimb}) snaps.$

Let's say I see "Charne applies intensive pressure. You howl as your right arm snaps."

My value is:

#if @targetlimb="right arm" {aff_brokenrightarm=1}

This doesn't seem to be working for me though. Is this the wrong syntax to be using in the value??
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Dec 08, 2008 2:05 am   
 
The reason why it's not working is it IS the wrong syntax. @targetlimb is a variable already set. It has several different limbs. In trigger patterns, you're most often looking for %1-%99.

Since you're using that pattern above, you could do

#VAR %concat("aff_broken",%subchar(%1," ")) 1

And what that will do is affix the broken limb without spaces to the aff_broken. So, with your example:

Charne applies intensive pressure. You howl as your right arm snaps.

Variable aff_brokenrightarm would be set to 1.

If it was left leg, then variable aff_brokenleftleg would be set to 1. :P

Hope this helps.

Charneus
Reply with quote
aedron
Beginner


Joined: 29 Nov 2008
Posts: 20

PostPosted: Mon Dec 08, 2008 5:24 am   
 
Wow, thank you Charneus! It works now. :D

One last question though, sometimes in that same reflex, when it hits chest gut or head it will give different ailments, is there a way I can still specify with the @targetlimb in the reflex? For example when the attack happens to the chest, the variable isn't aff_brokenchest.
It's aff_splinteredchest. Am I asking too much or does Zmud also have what I'm looking for?

The variables i use for the ailments are aff_brokenrightarm, etc for the limbs, aff_crackedskull for head, aff_fracturedchest for chest, and aff_dysentery for gut.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Mon Dec 08, 2008 7:52 am   
 
Heh... change the value from:

#VAR %concat("aff_broken",%subchar(%1," ")) 1

to

#IF (%1="head") {#VAR aff_crackedskull 1} {#IF (%1="chest") {#VAR aff_fracturedchest 1} {#IF (%1="gut") {#VAR aff_dysentery 1} {#VAR %concat("aff_broken",%subchar(%1," ")) 1}}}

Of course, in CMUD, you'd just use #SWITCH, but yeah... enjoy! :P

Charneus
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