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
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Apr 18, 2007 5:01 pm   

I'm drawing a blank (and incorrect results)
 
I'm working on a script that is supposed to automate a turn order for a game. However, it's kind of complex the way I have to do it. I start out with dice rolls, and then I sort those dice rolls. For further scripting purposes, I have to number their position. Maybe the code below will give some idea of what I need done.

After the initial dice rolls, my database stands like this:

PlayerA | 34
PlayerB | 42
PlayerC | 12
PlayerD | 59
PlayerE | 2
PlayerF | 80

After I sort the values, they are placed in proper order, in this case: PlayerE, PlayerC, PlayerA, PlayerB, PlayerD, PlayerF. What I need for it to do is take that turn order, and put their numerical position behind it, so it reads as follows:

PlayerE | 1
PlayerC | 2
PlayerA | 3
PlayerB | 4
PlayerD | 5
PlayerF | 6

I tried it with #loop 1,%numitems(@players) {#FORALL @players {#addkey turnorder %j %i}} and #forall @players {#loop 1,%numitems(@players) {#addkey turnorder %i %j}}, neither which produce the result I want. Does anyone have a suggestion for this? Thanks!

Charneus
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Apr 19, 2007 5:03 pm   
 
Hmm sounds familiar.
Have a look at this topic http://forums.zuggsoft.com/phpbb/viewtopic.php?t=10049
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Apr 19, 2007 8:02 pm   
 
Right - I've been using the sort for it, but it still doesn't change the values. It'll sort them in the order I want them to appear, but I need the values to be reset to a succession of numbers, i.e. PlayerA=23|PlayerB=28|PlayerC=44|PlayerD=62|PlayerE=78 needs to return PlayerA=1|PlayerB=2|PlayerC=3|PlayerD=4|PlayerE=5...

By the way, using what you suggested didn't work... this is what it returned:

Code:
#VARIABLE sortvar 35=Josh|50=Homer|45=Chris|99=Rezit|47=Barney|23=Skippy

#VARIABLE sortvar yppikS32yenraB74tizeR99sirhC54remoH05hsoJ53


As you can see, still not quite what I need. :P

Charneus
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Apr 19, 2007 9:24 pm   
 
First of all it looks like you didnt use the entire alias that i had written
It looks like you skipped a line or so because you the names are still going the wrong way.
Anyways lets see if we can do better.

Code:
#CLASS {DBNumericValSortB}
#ALIAS SortByVal {
  #var insort {}
  #var postsort {}
  #var insort %sort( %exec( "#loopdb %0 {#var insort %additem(%concat(%replace(%format('&7.f',%val),' ','0'),'=',%key),@insort)};@insort"))
  #var insort %subchar( @insort, "=|", %concat( %char( 30), %char( 29)))
  #var ndex 0
  #loopdb @insort {
    #add ndex 1
    #var postsort %addkey( @postsort, %val, @ndex)
    }
  }
#VAR postsort {} {}
#VAR ndex {}
#VAR insort {} {}
#CLASS 0


If you have a db variable named presort with the values you specified above:
PlayerA | 34
PlayerB | 42
PlayerC | 12
PlayerD | 59
PlayerE | 2
PlayerF | 80

SortByVal @presort
#showdb @postsort

Should show you this:

PlayerE: 1
PlayerC: 2
PlayerA: 3
PlayerB: 4
PlayerD: 5
PlayerF: 6



Thats what you wanted, no?
You said you were using a database variable, but if you want to use a string list and get the PlayerE=1 format
the #loopdb at the end could be changed to this
Code:
  #loopdb @insort {
    #add ndex 1
    #var postsort  %concat(@postsort,"|",%val,"=", @ndex))
    }


or something like that anyways. I didnt test the last code block
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Apr 19, 2007 10:16 pm   
 
AWESOME. You're my new hero, Dharkael. This is exactly what I was looking for.

Also... I copied everything into the alias for the last one. :\ Copy/paste from the forums, but it didn't work still. :\

Charneus
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Apr 19, 2007 10:35 pm   
 
Shrugs.
Oh well at least this scriptlet does what you want it to Wink

I'm pleased it worked out Very Happy
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
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