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


Joined: 18 Jan 2009
Posts: 8

PostPosted: Thu Oct 08, 2015 9:28 pm   

Pulling up a variable using a Trigger
 
Not sure how to phrase this so i'll give an example. I use the variable name in the (*) to hold a number so when its cast it should subtract and then show that number.

Pattern:
You utter the words, '(*)'

#add %1 -1 (this works, %1 being the variable i want to subtract from)
#say %1:@%1 (this doesn't work)

Also, the search function on the forum site doesn't seen to work it goes right to the web.
Reply with quote
shalimar
GURU


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

PostPosted: Thu Oct 08, 2015 9:59 pm   
 
Alright, a couple things.

1. %d is a better wildcard, as it will only pull numeric characters.
2. #ADD expects a named variable, %1 is an annonymous variable, instead you should be defining a new #VARIABLE, and likely a #LOCAL one
3. mathematical expressions should always be in parenthesis (%1-1)

So, you could do either of the following:

1:
#SAY {(%1-1)}

2:
#VAR number %1
#ADD number -1
#SAY @number

3:
number=(%1-1)
#SAY @number

4:
#LOCAL $number
#ADD $number %1
#ADD $number -1
#SAY $number

5:
$number=%1
#SAY {($number-1)}

These all perform the same action, only in the case of local variables ($number) the results are not saved, as a normal variable (@number) would be.
Anonymous variables (%1-%99) are also not saved.

Use the search option from under the site menu along the header.
_________________
Discord: Shalimarwildcat
Reply with quote
RichE
Newbie


Joined: 18 Jan 2009
Posts: 8

PostPosted: Thu Oct 08, 2015 10:11 pm   
 
Thank you for responding, this problem is driving me crazy.

Sorry, hard to explain, the value inside the (*) is supposed to be the variable name. So say its 'Lightning'. You utter the words, 'Lightning'
The variable Lightning has a value of say 9, this is pre-definied.

The trigger #add %1 -1, expands to #add Lightning - 1, so the variable Lightning now has a value of 8. This works in cmud. However, i want to show the new value in the script. Normally i would just put #say Lightning:@lightning, this would show the value 8, but i can't seem to couple the @ command to call the variable number stored and the %1 to choose that variable.

So for the trigger #say %1:@%1, The @%1 , which i know does not work is what i'm trying to do. Use the %1 to call the value of that variable.
Reply with quote
shalimar
GURU


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

PostPosted: Thu Oct 08, 2015 10:23 pm   
 
Aha, try this @{%1}
_________________
Discord: Shalimarwildcat
Reply with quote
RichE
Newbie


Joined: 18 Jan 2009
Posts: 8

PostPosted: Thu Oct 08, 2015 10:28 pm   
 
Shalimar, you are a genius. Thank you so much. Not sure why I couldn't find this in all the help files.
Reply with quote
shalimar
GURU


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

PostPosted: Thu Oct 08, 2015 10:30 pm   
 
It actually is mentioned in the help file for 'indirect variables'.
_________________
Discord: Shalimarwildcat
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Fri Oct 09, 2015 7:10 am   
 
While this may work fine, database variables are generally used for this. Depending on how complex this script becomes, it might be worth considering using a single database variable with the spell names as keys, rather than individual variables for each spell.
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