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
JWhitney
Wanderer


Joined: 20 Oct 2006
Posts: 51

PostPosted: Sun Aug 28, 2011 1:18 am   

Any way to use a temporary variable to point to another var's value?
 
Hello -

I'm not sure if this is really possible, but if it is, it would make my project much simpler.

What I am looking to do is have a temporary variable that contains the name of a regular variable, but use the temporary var to call the value of the regular.

Example output from MUD:
Code:
| Skill Name                 | 100 |


Trigger pattern:
Code:
^~| (%*) ~|(%*)~|


Trigger value:
Code:
#VAR skill_temp_left {%trimright(%1)}
#VAR skill_temp_left {%replace(@skill_temp_left," ",_)}
#VAR @skill_temp_left {%trimleft(%2)}
#IF (@skill_temp_left != @skill_temp_left_old) {#SAY SKILL % CHANGE}
#VAR skill_temp_left_old {%trimright(%1)}


In my MUD, blesses and other things can occur that will raise or lower a skill's %, so the purpose of this is to check if there is a difference in skill % from one moment to the next and alert me if so.

The first line defines the temporary variable with the skill's name, line 2 replaces any spaces in the skill's name with underscores, line 3 creates a regular variable with the adjusted skill name (skill_name) and defines it as the number in brackets (skill's %), fourth line tries to match the temporary variable's value to the previous time it was seen (this is where it fails), and the fifth line defines the 'last' time the skill was seen, what % it was.

What happens with the above code, is when it reaches line 4, @skill_temp_left = the adjusted skill name, and so does @skill_temp_old. What I'm trying to get it to do, is check if @(skill_name) = 100 is not equal to the old version, @(skill_name_old) = 90.

I apologize for my difficulty in communicating what goal I am trying to achieve. Thank you for reading this and making an attempt to understand what it is I intend to do.
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Sun Aug 28, 2011 1:30 am   
 
You are looking for Indirect Variables. The help files have some decent examples. I don't believe it works for setting values but it works very well for getting values.
_________________
"To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Sun Aug 28, 2011 1:52 pm   
 
It is quite clear what you're trying to do, and "Indirect Variables" is the topic you want... in short, use braces instead of parenthesis.

You can streamline the code by cutting out the extra variable and not capturing the spaces in the first place using the %s wildcard:
Code:
#TR {~|%s(*)%s~|%s(%n)%s~|} {
  #IF (%2 != @{%replace(%1," ","_")}) {
    #ECHO %1 changed by %eval(%2-@{%replace(%1," ","_")})%
    #VAR {%replace(%1," ","_")} %2
    }
  }
_________________
.geniusclown
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