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


Joined: 14 Mar 2009
Posts: 3

PostPosted: Sat Mar 14, 2009 8:30 am   

search "Data Record" by value, not key
 
I'm not using a db... just using #addkey to create "variables" with key->value pairs.
(like a perl hash)

I'd like to return the keys with a matching value and dump that into an array. But, everything I'm finding seems to return the value by key or requires the use of a db. Am I missing something? Suggestions? Advice?
Reply with quote
kogitov
Newbie


Joined: 14 Mar 2009
Posts: 3

PostPosted: Sat Mar 14, 2009 8:58 am   
 
I just realized, while it makes perfect sense to me, it might be a little cloudy to someone who doesn't know exactly what I'm doing... so here's a simplified example:

#Trigger {^Your (*) is (%w).$} {#AddKey Injuries (%1=%2}

Mud:
Your left arm is scratched.
Your right leg is bruised.
Your left big toe is gaping.
Your torso is bruised.
Your head is gone.

Now, @Injuries's value is:
left arm|scratched
right leg|bruised
left big toe|gaping
torso|bruised
head|gone


What I'd like to do from here is type "heal @prioritylimb" and assume my head will be glued back on first. Of course, if you're head's gone, you're going to want to treat that problem first. So, player would: "use healing head", "use healing torso", "use healing left arm", "right leg", ending with the big toe (as it can wait until the battle is over) whatever... (the order is the goal)

So, to help automate the healing decisions, I want to write a logic structure that, first checks for "gone" limbs, then "gaping", then "bleeding", then "scratched", then "bruised", while considering that some limbs are more important (torso vs left arm) ...

Bare in mind, this is a simplified example. Suffice it to say that healing doesn't solve the problem, completely, most of the time. Sometimes multiple applications may need to be used. Let's say my healing script uses the variable @prioritylimb... and I need to put the appropriate limb into that variable in the background so, when I have a chance to heal, I don't have to figure out which one is worst-off, I can simply heal @prioritylimb ... and count on my series of #IFs to have organized the array that feeds @prioritylimb, (let's call it:) @healorder, so that I can call on it quickly and reload @prioritylimb when I'm done healing (or satisfied with the current level of healing).

The problem is that I can't figure out how to call name of the limb based on its level of injury out of the "Data Record". I would want to heal all "gone" limbs first, then head and torso(whichever is worse off, preferably), then extremities (again, starting with worst-off).

... follow? good.
Help?
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Sat Mar 14, 2009 9:01 am   
 
#loopdb @yourvar {#if (%key == "your string here") {do something nice}}

But really, depending on the size of your db, this is going to be slow, so if you're going to want to do this often you should change your variable so that it works more naturally. Maybe if you have a lot of keys and only a few distinct values, it would be easier to just keep them in stringlists to start with.

Edit: On reading further information, let me think about it for a while.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat Mar 14, 2009 3:20 pm   
 
%isvalue

use healing %item(@db,%isvalue(@db,"gaping"))
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sat Mar 14, 2009 3:23 pm   
 
I'd suggest making the process to add stuff into Injuries DB Var a little bit more complex.

Basically, you know for a fact the order in which you want to heal stuff.

So make a String List that will basically list things you want to heal, using syntax, say, "1_scratched" or something.

This list is made when you encounter some message which says that some body part of yours is hurt.
Into one String List you'd enter part that's hurt, into another one how it's hurt exactly.

#trigger {Your (%w) is (%w).} {#additem HurtPart {head};#additem HealStuff {001_gone}}

Now you'd have Event or Alarm or whatever which will become active when HealStuff has something inside of it.

Then it would sort the latter list, given that there are several places that are hurt, you can use %sort within script
or just tick the Sorted by Variable.

Then it'll be the question of healing stuff in turns, popping one off each variable while doing it

heal %pop(HurtPart)

When message it's healed is seen, you use same %pop with HealStuff variable
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
kogitov
Newbie


Joined: 14 Mar 2009
Posts: 3

PostPosted: Sun Mar 15, 2009 8:31 am   
 
gamma_ray wrote:
#loopdb @yourvar {#if (%key == "your string here") {do something nice}}

I'd need to search the data record (not database) by the value of the key, first... to see if anything's "gone"... which makes it top priority. If I ignore the ideal task of prioritizing "gone" limbs (let's face it, anything missing is a priority... at that point its nitpicking), then I can accomplish this, first, with
Code:
#LoopDB @Injuries {#IF (%val == "gone") {#AddItem DamagedLimbs %key}


But, then, I have the problem of repeated limbs in the @DamagedLimbs, once I prioritize the rest of it. I tried working with that solution, and I just can't seem to sort out the logic to get it to work the way I want. This may be the right track, but I'm at a loss of how to make it work.

Fang Xianfu wrote:
%isvalue

use healing %item(@db,%isvalue(@db,"gaping"))

I believe this is essentially what I'm looking for... except for one problem. When I clicked "New Post" I was searching the zmud General Discussion and failed to notice that the new post was started in the cmud General discussion. After checking the zmud help files, there doesn't appear to be a %isvalue function.

Progonoi wrote:
#trigger {Your (%w) is (%w).} {#additem HurtPart {head};#additem HealStuff {001_gone}}

Maybe I'm not understanding correctly, but as I see it, you're having me create two separate arrays. If I %sort(@Healstuff), then wouldn't the order of @healstuff and @hurtpart be different or am I misunderstanding the value of %sort?

-------

The issue is like this... I have certain things that need to be healed first, such as head or torso then appendages then phalanges. UNLESS, something else has reached critical damage... in which case that becomes priority (even a toe). If the level of damage weren't to be considered, I could simply slap each injured item into an array ("Variable"/"string list") and write a function ("alias") to sort it, and spit out another array. I essentially need to do that anyway, but, I need to dynamically bump anything critical (ie. 'gone') to the top of the list (ie. so I don't bleed to death).

Its consistently late when I work on this project. Maybe I'm having so much trouble because I need a fresh perspective. Its pushin' sun-up... I'm going to bed. Here's my progress, as it stands. It doesn't work, but you can see where I'm trying to go with it. The %db and %ExpandDB functions don't appear to apply. Maybe the problem is that zScript was never intended to be used with "Data Records" ... and they exist soley for VBscript/Jscript compatibility? I used %pos with %ExpandDB to attempt to determine if the limb exists, at all, in @Injuries. ... Is #ForAll essentially the same as ForEach in other languages (thinkin' of perl).

(@LimbPriority is a list of limbs in order of importance.)
Code:
#Var HealList
#ForAll @LimbPriority {#IF (%db( @Injuries, %i) == "Inoperative") {#AddItem HealList %i}}
#ForAll @LimbPriority {#IF (%db( @Injuries, %i) == "Heavy") {#AddItem HealList %i}}
#ForAll @LimbPriority {#IF %pos( %i, %ExpandDB( Injuries)) {#AddItem HealList %i}}
#Var NextHeal %pop( HealList)


Also, could I get an admin to bump this to zmud, please? My mistake.
Thanks!
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sun Mar 15, 2009 3:24 pm   
 
I have to think some more about it, because I think I understand what you're after.
You need to sort the values of the database variable and based on that add keys of the same db var into healing list, right?

I must say though, that I'm unsure how doable it would be under ZMud. Under CMud there are a lot of functions which
would serve purpose here though. Fang mentioned %isvalue, but there are also %dbvalues, %dbkeys and of course possibility
to use Local Variables which would do a large bunch of work here.

I'm going to think about it some more unless someone else comes up with an idea. But I have to say that there might not
be many ways to skin this one. Or maybe I'm just stupid because I haven't really coded for close to a year now.
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sun Mar 15, 2009 6:19 pm   
 
Use %isvalue. It's simple, it works, and it requires no looping.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Sun Mar 15, 2009 6:54 pm   
 
As it's already pointed out by OP, he mistakenly posted this as a CMud thread.

However, while scripting all this in CMud would definitely be very nice, I think I came up with some sort of idea how to solve your problem.

Imagine the above:

1) You have several triggers that add data to a DB Var, they're like this:
Code:

#trigger {Your (%w) is (%w).} {#addkey Injuries {%1} {%2}}


Now, you know for a fact that some are far worse than others, like "gone"
With that in mind, you could do this:
Code:

#trigger {Your (%w) is (%w).} {#if (%2="gone") {#addkey Injuries {%1} {%concat("001_",%2}};
#if (%2="bruised") {#addkey Injuries {%1} {%concat("002_",%2}};
#if (%2="scratched") {#addkey Injuries {%1} {%concat("003_",%2}}}


Now you'd have a DB Var which has defected body part as Key and the magnitude of defect as Value:
Code:

head - 001_gone
left arm - 002_bruised
right leg - 003_scratched


The numbers will work as an element which would help you sort them properly to the correct healing order.

Now you need to form a list which you can sort and based on that form your HealList.
Idea I had possibly looks ugly but at this point I don't know how else to solve it under ZMud because it's obvious that
the best way for capturing the data you need is by initial DB Var.

Anyway,

Code:

#loopdb @Injuries {#additem HealData {%concat(%val,"$",%key)}}
#forall %sort(@HealData) {#additem HealList {%subregex(%i,"\d+\_\w+\$(\w+)",\1)}
#var HealNext {%pop(HealList)
_________________
The Proud new owner of CMud.

--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
--------------------------------
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