|
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Thu Jun 07, 2012 3:27 pm
Tying Records and Stringlists together |
Alright, I've been messing with this for a good while but just can't seem to get it sorted out right.
Affliction String list – paralysis, crippled, epilepsy, stupidity, confusion
I’ve got a record file(AfflictTypes): that has the following:
Crippled | Bloodroot
Paralysis | Bloodroot
Stupidity | Goldenseal
Epilepsy | Goldenseal
Confusion | Ash
So I’ve got a function to check the string list and compare it to the record.. If I have paralysis.. it then refers to the Bloodroot stringlist.
Bloodroot contains:
Paralysis
Mirroring
Crippled Body
Crippled
Slickness
heartflutter
sandrot
Basically, I want the function to take the affliction string list and compare it to the AfflictTypes. The AfflictTypes record is sorted in the order of importance. As soon as it compares it sees crippled is the most important and checks the bloodroot stringlist. When it checks the bloodroot string list it notices that paralysis will be cured before crippled so it says I’ll be curing crippled. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Thu Jun 07, 2012 6:12 pm |
Something like this should work, but it is untested.
#IF (@affliction) {
$affliction=%item(@affliction, 1)
$cured=@cures(@afflicTypes.${affliction})
#PRINT {I'll be curing $cured}
}
#FUNC cures($herb) {
#FORALL @{$herb} {
#IF (%ismember(%i, @affliction)) {
#RETURN %i
#EXIT
}}} |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Thu Jun 07, 2012 10:39 pm |
Yea, doesn't work sadly. Also, doesn't prioritize by the order of AfflictTypes. I want it to cure in the order of afflicttypes.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Fri Jun 08, 2012 4:29 am |
then you should try nesting your DB variables differently
#ADDKEY herbs.bloodroot {1=Paralysis}
then you can loop through %dbkeys |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Mon Jun 18, 2012 9:10 pm |
Any other ideas? Been trying to play with shalimar's but still not getting what I want. I can further explain if need be.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Jun 18, 2012 11:43 pm |
You'll have to explain further.
|
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Wed Jun 27, 2012 9:04 pm |
Sorry, I went to change my account email and it shut down my account. Seems zuggsoft isn't replying very quickly so I made another account.
Code: |
$SalvePick = 1
$PotPick = 1
$HerbPick = 1
$FocusPick = 1
$AllhealePick = 1
tcurelist = %null
TryCure = %null
#Loopdb @AfflictTypes {
// Loop through all afflict types and see if member
// of tempafflict.
#if (%ismember( %key, @tempafflict)) {
// Check different balances to add the items appropriately.
#if ((%ismember( %key, @salvelist)) and $SalvePick = 1 and @balances.salvbal = 1 and (!%ismember( %key, @tcurelist))) {
#additem tcurelist %val
$SalvePick = 0
}
#if ((%ismember( %key, @potlist)) and $PotPick = 1 and @balances.potbal = 1 and (!%ismember( %key, @tcurelist))) {
#additem tcurelist %val
$PotPick = 0
}
#if ((%ismember( %key, @herblist)) and $HerbPick = 1 and @balances.herbbal = 1 and (!%ismember( %key, @tcurelist))) {
#additem tcurelist %val
$HerbPick = 0
}
#if ((%ismember( %key, @focuslist)) and $FocusPick = 1 and @balances.focusbal = 1 and (!%ismember( %key, @tcurelist))) {
#additem tcurelist %val
$FocusPick = 0
}
#if ((%ismember( %key, @allhealelist)) and $AllhealePick = 1 and @balances.char.vitals.tree= 1 and (!%ismember( %key, @tcurelist))) {
#additem tcurelist %val
$AllhealePick = 0
}
// Adds the herb name to tcurelist
}
}
// Check the herbs in tcurelist and get the correct
// healing order.
#if (%ismember( goldenseal, @tcurelist)) {
#switch (%ismember( self-pity, @tempafflict)) {#additem TryCure "self-pity"}
(%ismember( stupidity, @tempafflict)) {#additem TryCure "stupidity"}
(%ismember( epilepesy, @tempafflict)) {#additem TryCure "epilepsy"}
#say I'd eat goldenseal here
}
#if (%ismember( bloodroot, @tcurelist)) {
#switch (%ismember( paralysis, @tempafflict)) {#additem TryCure "paralysis"}
(%ismember( crippled, @tempafflict)) {#additem TryCure "crippled"}
#say I'd eat bloodroot here
}
#if (%ismember( ash, @tcurelist)) {
#switch (%ismember( confusion, @tempafflict)) {#additem TryCure "confusion"}
#say I'd eat ash here
}
#say In the end I'd try to cure @TryCure |
Not sure if that makes more sense.. but it's the closest to what I'm wanting to do.
EDIT: added code tags (MattLofton) |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Jun 28, 2012 12:24 am |
As a suggestion, when you want to include code in your post, put [code] at the beginning of the code, and [/code] at the end of the code. That will preserve exact spacing, which is important in code, like this:
Code: |
#IF (anything) {
#show Something
}
|
Now, you've given us the code. What exactly is not working the way you want? |
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Thu Jun 28, 2012 4:18 pm |
Basically now just trying to see how to make the code more clean.. I'm starting to get what I want..
AfflictTypes stores a host of afflictions/cures..
Example:
Affliction | Herb
Crippled | Bloodroot
Paralysis | Bloodroot
Stupidity | Goldenseal
Epilepsy | Goldenseal
Confusion | Ash
TempAfflict holds afflictions that are currently on my person..
Example:
paralysis, crippled, epilepsy, stupidity, confusion
I want to be able to loop through tempafflict to check for its herb and then see what it is curing.
So Crippled is the first in priority.. I want to cure it before anything else, it would loop through tempafflict
and see crippled as the first priority in AfflictTypes. So it'll try to cure with bloodroot.
Now I want it to check through bloodroot.. Bloodroot cures in a certain order itself..
Bloodroot contains:
Mirroring
Paralysis
Crippled Body
Crippled
Slickness
heartflutter
sandrot
So the system wants to cure crippled first but realizes that eating bloodroot will actually cure paralysis first.
So it registers, I am curing paralysis at this moment. |
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Thu Jun 28, 2012 4:26 pm |
Oh yea.. one more edition.. I'd really like it to go through tempafflict rather than AfflictTypes.
AfflictTypes will be holding about 300 records... while tempafflict will only be holding like 3-4 items.
I just couldn't figure out a way to do it that way. I think it'd run much smoother if it didn't have to process that much. |
|
|
|
Tarn GURU
Joined: 10 Oct 2000 Posts: 873 Location: USA
|
Posted: Thu Jun 28, 2012 6:24 pm |
Rastamutti wrote: |
Oh yea.. one more edition.. I'd really like it to go through tempafflict rather than AfflictTypes.
AfflictTypes will be holding about 300 records... while tempafflict will only be holding like 3-4 items.
I just couldn't figure out a way to do it that way. I think it'd run much smoother if it didn't have to process that much. |
If the script isn't working (producing what you expect from what you put in), we can help.
If you want to make it better, we would need to understand more about what you're trying to do.
Which mud is this? The system looks similar to the Iron Realms ones (afflictions/cures) but the behaviour and afflictions don't match Achaea, which is the one I'm most familiar with.
Example of a possible improvement: use CMUD's keyed DB to store things instead of a huge list that you loop through. Then, you'd loop through the afflictions you currently have and use the keyed lookup to find out what the appropriate cures are. Ref
http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2727
-Tarn |
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Thu Jun 28, 2012 9:53 pm |
It's Aetolia... I'm not sure how else to explain this. The code I've done so far seems to be doing
the job but I'm trying to see if there is a better way. Looping through ALL my AfflictTypes(300+ records)
to check for 4 or 5 things just doesn't seem efficient. The rest seems to work but I'm figuring there is a better
way.
I'm not sure how to explain this any better.
I get afflictions.. I run it through my affliction track data base to find the affliction and the cure.
I then check it against the cure file to see which it's going to cure. As you know, plants cure multiple
afflictions in a certain order.. If I'm trying to cure paralysis but I've got something else ahead of it
in the herb order, then I'm going to cure that instead. I want the system to track this and expect it.
Not sure how else to put it. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Jun 28, 2012 10:55 pm |
If it's working, don't try to fix it. If you want some specific improvement, then try to describe what you want. You have a very complex piece of code here, and trying to fix it when it isn't broken may really break it. If it is truly slowing things down, then you might want to fix that, but simply looking for something more efficient when you aren't sure you need it is asking for trouble.
|
|
|
|
Tarn GURU
Joined: 10 Oct 2000 Posts: 873 Location: USA
|
Posted: Thu Jun 28, 2012 11:31 pm |
Rastamutti wrote: |
It's Aetolia... I'm not sure how else to explain this. The code I've done so far seems to be doing
the job but I'm trying to see if there is a better way.
|
There's always a better way :)
Quote: |
Looping through ALL my AfflictTypes(300+ records)
to check for 4 or 5 things just doesn't seem efficient. The rest seems to work but I'm figuring there is a better
way.
|
That is a lot of unnecessary work, but as Rahab says what isn't causing problems doesn't need fixing.
Quote: |
I get afflictions.. I run it through my affliction track data base to find the affliction and the cure.
I then check it against the cure file to see which it's going to cure. As you know, plants cure multiple
afflictions in a certain order..
|
No, I didn't know. On Achaea, they switched to random order some time back.
Quote: |
If I'm trying to cure paralysis but I've got something else ahead of it
in the herb order, then I'm going to cure that instead. I want the system to track this and expect it.
|
Ah, ok- so you're figuring out what cured message to expect back from the server so you can reject non-matching ones as illusions.
I don't see why you would need to rummage through the huge affliction list.
At worst, once you decide that you're going to use bloodroot, can't you just go through the Bloodroot-cure-order-list in order checking each to see if it's in your current afflictions list?
I think you could probably avoid running the big #Loopdb @afflicttypes at the beginning of your code every time by running through it once and using it to build up a priority list for curing and a separate keyed db variable which lets you look up the cure for each.
There are also a couple of tricks available for sorting. One of them, making up priorities and order: if your affliction list is "paralysis|crippled|asthma|epilepsy" use a lookup table to turn that into a renamed "01_paralysis|04_crippled|10_asthma|05_epilepsy". The point is that the renamed values were picked so that sorting them alphabetically is the same as their priority order. Then, use CMUD's sort function to get "01_paralysis|04_crippled|05_epilepsy|10_asthma", then look up the cure for what's highest (paralysis) and then look up what that cure will actually cure first from this list. |
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Fri Jun 29, 2012 12:08 am |
Thanks guys.. Think I actually know a better way to say what I want now.. I'll put it more in code and see if you know a way to do
it.
Can just do a
Code: |
#forall @tempafflict {
#if (%iskey(@AfflictType, %i) {
#additem tcurelist %val
}
} |
Anyway I'm able to do something along those lines? Go through all the tempafflict, check it against
AfflictType, then add the value to my tcurelist?
btw, Tarn I read your suggestion this just seems a bit easier for me.. Yours would take me a bit to figure out what
you're talking about. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Fri Jun 29, 2012 4:18 am |
Rastamutti wrote: |
Can just do a
Code: |
#forall @tempafflict {
#if (%iskey(@AfflictType, %i) {
#additem tcurelist %val
}
} |
|
There is no %val in that loop - %key and %val are only available in a #loopdb. I believe you want %db(@AfflictType, %i). |
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Fri Jun 29, 2012 5:50 am |
Perfect! Thanks very much folks! Finally got what I was looking for! Thanks for dealing with my..
lack of explanation. |
|
|
|
Rastamutti Beginner
Joined: 27 Jun 2012 Posts: 17
|
Posted: Sat Jun 30, 2012 1:41 am |
So close.. but so far away.. Everything is working fine now except one problem..
AfflictTypes can't be arranged in a priority order. The first thing in its record I want to be the priority to the last thing being the least important.
Any idea how to make it let me set an order? |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Sat Jun 30, 2012 2:02 am |
You can't keep database variable items in a certain specific order unless you use the built-in sorting, which is only by alphabetical or numerical, not what you want. Your best bet is probably to rename your AfflictTypes database variable to Cures or something, then make a new AfflictTypes string list which will just have the keys, in the priority you want. Unlike database variables, items in string lists will stay in the order you specify.
|
|
|
|
|
|