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


Joined: 09 Apr 2016
Posts: 3

PostPosted: Thu Apr 14, 2016 8:56 pm   

Help creating an alias to display variables
 
Hi, I play a mud that doesn't assign numbers to skill levels. Instead it uses words, so I keep track of the level of each individual skill with a variable. When the skill goes up in level, I have a trigger to {#ad skill 1;#show @skill}. All of these variables are kept in a class folder.

What I'm trying to do is display all of these variables at once, in order. I made a really basic alias that's like -

{displayskill} {#say %1;#show @%1}

and it works great for individual variables. But I want to display the entire class, in order, from lowest number to highest number, in this fashion. I thought about making a long alias like {displayskill swordfighting;displayskill climbing etc.} for every variable, but that would be a lengthy process, and wouldn't keep the numbers in order. I'm sure there's an easier way to do this, if you could help at all that'd be great. Thanks!
Reply with quote
shalimar
GURU


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

PostPosted: Fri Apr 15, 2016 1:31 am   
 
Well, with the set up you have now, that long way may be your best option.
However, if you were to update your skill tracker to use a variable database, it would be much easier.

You could make do with a variable list of all the various skills to be referenced by the alias.

#FORALL @skillList {#SAY %i;#SHOW @%i}
_________________
Discord: Shalimarwildcat
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Apr 16, 2016 7:25 am   
 
Converting to a record variable would be best, especially since you would need one in order to do the sorted display you want. Here is a hastily written alias to display the variable. You might modify it to do the conversion for you, see #ADDKEY.
Code:
#ALIAS ListClassVars {
 #LOOP %session.NumVars {
  $var=%session.VarNum(%i)
  #IF ($var.ClassName==%1) {#SHOW {%concat($var.Name," = ",$var.Value)}}
 }
}

For more information on how it works read Predefined Variables and zMud as a COM Server

When you have it in a record variable it would look something like:
skill1=12|skill2=8|skill3=19|skill4=8

And you are saying you want to sort by the values portion. The easiest way to do that is to reverse the value and key positions in the variable:
recVar=%subregex(@recVar,"([^=|]+)(?:=([^|]*))?(?=\||\Z)", "%rightback(%concat(""0000"",\2),4)=\1")

Assuming I wrote all of it correctly that would convert my above example to:
0012=skill1|0008=skill2|0019=skill3|0008=skill4

You can then use %sort to get the ordering you want and #SHOWDB or #LOOPDB to produce the display you want.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
shalimar
GURU


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

PostPosted: Sat Apr 16, 2016 2:16 pm   
 
You are not accounting for the chance that two skills might share the same current value.
_________________
Discord: Shalimarwildcat
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Apr 17, 2016 5:21 am   
 
I used %subregex to swap the key=value to value=key on the string representation of the record variable, it is a low level hack. You can have multiples of the same key; #ADDKEY doesn't allow it but it does work, and which of the values gets returned by %db or dot notation is undefined. None of those are a problem for this usage since %sort doesn't actually know record variables, and #LOOPDB or #SHOWDB will be working with all records sequentially.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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