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
Zygote
Newbie


Joined: 07 Dec 2009
Posts: 9

PostPosted: Mon Dec 07, 2009 1:12 am   

retaining variables
 
What's the syntax for using one variable in two triggers? I have a scenario like this:

search garden <command sent to mud
You find carrots in the garden. <mud output
gather carrots <command sent to mud
...gather gather gather spam...
You are tired of digging and rest a while. <mud output
gather carrots <command sent to mud
...gather gather gather spam...
You realize you have gathered all the carrots in the garden. <mud output

I'd like to use a trigger to capture whatever vegetable is found and dump it into a variable
Use that variable in the 'gather' command
Use that same variable again to start gathering when the mud outputs 'You are tired of digging and rest a while.'

Thanks!
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Dec 07, 2009 4:23 pm   
 
Just use an ordinary variable. The command "#var myvariable newvalue" can be used to set the value, and the form "@myvariable" can be used in other triggers or aliases to pull the value.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Mon Dec 07, 2009 4:40 pm   
 
A simple trigger is:
Code:

#TRIGGER {You find (*) in the garden.} {#VAR vegetable %1;gather @vegetable}

for the first type of action.
Reply with quote
Zygote
Newbie


Joined: 07 Dec 2009
Posts: 9

PostPosted: Mon Dec 07, 2009 4:42 pm   
 
Thanks! How do i assign the variable using a trigger? So when the output/trigger 'You find carrots in the garden' fires,
carrot gets assigned that variable?
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Mon Dec 07, 2009 7:17 pm   
 
The trigger I posted does that.
Reply with quote
Zygote
Newbie


Joined: 07 Dec 2009
Posts: 9

PostPosted: Tue Dec 08, 2009 4:51 pm   
 
Thanks so much! I was trying to do everything in one line and it just wasn't working! Works great now!
Reply with quote
Zygote
Newbie


Joined: 07 Dec 2009
Posts: 9

PostPosted: Thu Dec 10, 2009 7:16 pm   
 
I've been playing with this and got it to work, and now I'm trying to expand on it. I've been reading about triggers, pattern matching and variables and trying different things but nothing has worked yet. Here's what I'm trying to achieve and what my last (failed) attempt was:

Search and find multiple things (As you dig you find carrots, spinach and onions)
put each vegetable in it's own (global) variable
use one of the variables in a command (you pick <var for carrots>)
start picking next vegetable when that one is gone
trigger:you don't see anymore carrots
command:pick <var for spinach>)

What I've tried:
Trigger: you find @veg1, @veg2 and @veg3
Command: pick @veg1

I've also tried:
Trigger: you find %w, %w and %w
Command: #VAR veg1 %1
#VAR veg2 %2
#VAR veg3 %3
pick @veg1

I obviously don't know what I'm doing and would appreciate any help you might be able to lend. thanks a bunch!
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Dec 10, 2009 9:22 pm   
 
You are overcomplicating things a bit... unless you plan on reusing the variables for something, each vegetable does not needs its own variable.
These settings will cycle through all three vegetable types, and stop when the third is finished

#ALIAS getVeggies {#VAR veggies {carrot|spinach|onion};#VAR thisVeggie %pop(veggies);gather @thisVeggie}
#TRIGGER {You find (*) in the garden.} {gather @thisVeggie}
#TRIGGER {You are tired of digging and rest a while} {gather @thisVeggie}
#TRIGGER {You don't see anymore} {#IF (@veggies) {#VAR thisVeggie %pop(veggies);gather @thisVeggie}}
_________________
Discord: Shalimarwildcat
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Dec 10, 2009 9:37 pm   
 
[ninja'd!]

Actually, the way I would do it is with a single stringlist. A stringlist is several values packed into a single variable. So, assuming your mud text looks like:
You find carrots, spinach and onions in the garden.
You are tired of digging and rest a while.
You realize you have gathered all the carrots in the garden.

I would code it:
Code:

#TRIGGER {You find (*) in the garden.} {#VAR veggies %replace(%replace(%1,", ","|")," and ","|");#VAR currentveggie %pop(@veggies);#IF (@currentveggie) {#SEND gather @currenveggie}}
#TRIGGER {You are tired of digging and rest a while.} {#SEND gather @currentveggie}
#TRIGGER {You realize you have gathered all the * in the garden.} {#VAR currentveggie %pop(@veggies);#IF (@currentveggie) {#SEND gather @currenveggie}}

The %replace() functions in that code change "carrots, spinach and onions" into "carrots|spinach|onions", which gets interpreted as a stringlist of three strings. The %pop returns the first string of the stringlist (where it ends up in the @currentveggie variable) and deletes that value from the stringlist. So, this code sequentially runs through the entire list of vegetables. The #if checks whether there is any value left in @currentveggie, before doing the next gather command.
Reply with quote
Zygote
Newbie


Joined: 07 Dec 2009
Posts: 9

PostPosted: Thu Dec 10, 2009 9:51 pm   
 
thanks so much for the input!
I have a question about shalimar's post -
the problem is, any combination of vegetables could be returned (it could be squash, beans and spinach). This line assigns the specific vegetables carrot, spinach and onion to the variable 'veggies', no?
#ALIAS getVeggies {#VAR veggies {carrot|spinach|onion};#VAR thisVeggie %pop(veggies);gather @thisVeggie}
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Dec 11, 2009 1:48 pm   
 
Yes, Shalimar's example only put the specific vegetables carrot, spinach, and onion to the variable veggies. I presume he gave that as a simple example of setting a stringlist variable and left the implementation of capturing the correct vegetables to you. My example gave a method of extracting the vegetable names from the trigger phrase.
Reply with quote
Zygote
Newbie


Joined: 07 Dec 2009
Posts: 9

PostPosted: Fri Dec 11, 2009 4:22 pm   
 
Thanks Rahab - the code you passed along is working great, and I learned a little more! The replace function is pretty cool.
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