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


Joined: 19 Jul 2007
Posts: 18

PostPosted: Mon Dec 31, 2007 10:17 pm   

Variables / Data records
 
Pehaps I haven't figured out the syntax, but this is what i'm attempting to do:

I have several variables that are setup as data records, to collect racial attributes.
My currrent script will collect and update the data records as I want, and I can display the data.
However, I would like to sort the display in a better order.

This is the current variable:
#VAR halfling_race {Energy-20Mental41Poison19 Water-40 Bash55 } {_nodef} "RACEINFO|RacialVulns"


And this is the current alias to access/display the data:
#IF (@playerrace = "Halfling") {
#LOOPDB @halfling_race {#IF (%val < 0) {#SHOW @playername Vuln:%key "=" %val}}
#LOOPDB @halfling_race {#IF (%val > 0) {#SHOW @playername Resist:%key "=" %val}}
#class Racecheck 0
}


The output looks like this:
player Vuln : Energy = -20
player Vuln : Water = -40
player Resist: Mental = 41
player Resist: Poison = 19
player Resist: Bash = 55

What I would *like* to do, is somehow sort each output so that each racial resist is in decreasing order, and each racial vuln is in increasing order.

I've looked at the #SORT and %sort options, but I haven't been able to use either to get any desirable output. It could be syntax problems on my part.

I'd like the outputs to look more like:
player Vuln : Water = -40
player Vuln : Energy = -20
player Resist: Bash = 55
player Resist: Mental = 41
player Resist: Poison = 19

or even more ideally:
player Vuln : Water = -40, Energy = -20 <-----in increasing order
player Resist: Bash = 55, Mental = 41, Poison = 19 <-----in decreasing order

Any tips or suggestions would be appreciated, or even suggestions into the help files that I mave have overlooked.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Tue Jan 01, 2008 10:56 pm   
 
#sort is a CMUD command. Is this a question about CMUD or zMUD?

You won't be able to get the two halves sorted in different orders using a single variable with the #sort command. You'll have to make your own sorter - the easiest way to do that would probably be to build a reverse table and a string list of the values, sort the string list and then pull the keys from the reverse table. Sort of like this:

#loopdb @halfling_race {#additem values %val;#addkey tempreverse %val %key}
#forall %sort(@values) {#if (%i > 0) {#say Resist: %db(@tempreverse,%i) = %i}
#forall %sort(@values) {#if (%i < 0) {#say Vuln: %db(@tempreverse,%i) = %i}

This assumes that the values are unique, though - if they're not always unique, you'll need to handle that situation somehow.
_________________
Rorso's syntax colouriser.

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


Joined: 19 Jul 2007
Posts: 18

PostPosted: Wed Jan 02, 2008 11:16 am   
 
yeah, this is for Zmud... but the %sort and #SORT both come up in zmud help files.

I think I see what you have on your script. Let me try tinkering and see what happens with that.
Thanks!!
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