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


Joined: 14 Oct 2009
Posts: 57

PostPosted: Wed Oct 14, 2009 9:09 am   

Trying to dip my toes in %db. needing some help please!
 
Hi guys, I have a rather long healing script and i was wanting to improve on it dramatically to increase its speed mostly... currently i do something like this


#IF ((!@herbcure) and (%ISMEMBER( "rarm", @myafflictions)) AND (!%ISMEMBER( "rarm", @tryafflictions))) {
addtry rarm
Herbcure = 1
healingherb
herbdelay
}
#IF ((!@herbcure) and (%ISMEMBER( "paralysis", @myafflictions)) AND (!%ISMEMBER( "paralysis", @tryafflictions))) {
addtry paralysis
Herbcure = 1
eattreeleaf
herbdelay
}

and this list goes on for about 30 different damage types.

What im trying to do is cut them all down to a single query where in @afflictions there is each affliction with thier cure in order of importance

#VAR afflictions {}
#ADDKEY afflictions {RARM} {healingherb}
#ADDKEY SalveCures {paralysis} {eattreeleaf}

so now it would cut down all 30+ different #ifs down to

sort the @myafflictions in order of importance (higher up the @afflictions it is, the more important it is)
then if the first in the list of @myafflictions was not a member of the variable @tryafflictions
eat the herb listed in @afflictions for the affliction listed first in @myafflictions

any ideas?


i hope this makes sence to somebody. ive been trying for days!
Reply with quote
Fidel
Beginner


Joined: 07 Oct 2009
Posts: 19
Location: Poland

PostPosted: Wed Oct 14, 2009 10:28 am   
 
Hi,
I don't know if I understood you properly but if you want one list with key containing two values you can either use Database Module where you can store Key, Val1, Val2 in 3 columns.

Or simply put to "database record" variable using #ADDKEY key "val1|val2" and "%db().%1" for first value and "%db().%2" for the second

Hope this helps
Paweł
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Oct 14, 2009 1:38 pm   
 
Let me see if I understand what you want. You have a dabatase variable, @afflictions={RARM=healingherb|paralysis=eattreeleaf|foobar=baz}, and you want the keys to be in a particular order?

If that's what you want, you will have to do it a different way. Database variables are hashed, to increase access speed, and there is no guarantee about the order of the keys (unless you set it to be alphabetically sorted). An alternative method of doing what you want would be to make the database variable as you have, and have a SEPARATE variable containing a stringlist of just the keys, in the order you want. Then you can loop through the list with a #FORALL, possibly breaking out of the loop with #BREAK or #CONTINUE.
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