|
inimical Beginner
Joined: 12 Aug 2003 Posts: 14
|
Posted: Tue Aug 12, 2003 3:41 am
comparing data records |
I have a few questions regarding data record variables. First is concerning this bit of code
Code: |
#trig {~((*)~) a sprig of (*)} {
#loopdb @SprigCheck {
#if (%key=%2) {
#var SprigCheck.%remove( " ", %2) {1}
#var SprigCount.%remove( " ", %2) {%remove( " ", ~(%1~))
}}}}
|
The idea is to check what sprigs I have, and how many of each by assigning the number in %1 to SprigCount and setting the values in SprigCheck to 1 for those I have. An alias zeros those values before this script is run. Now it works fine, just the way its supposed to, but it seems slow. Is this an inherent issue with looping databases or is there a way to script this more effectively?
My second question is about comparing data records using conditionals. This is a piece of code that doesn't work at this point but should get the idea of what I'm trying to do across.
Code: |
#alias herb {mixnum=%1;mixtype=%2}
#var mixpower {0}
#math remainder (@max-@mixpower)
#loopdb @SprigPower {
#if ((%val<=@remainder) AND (@SprigCheck.%key=1) AND (@SprigCount.%key>=@mixnum)) {
#if (%key=linguacanis) {herb=lingua}
#if (%key=virgapastoris) {herb=virga}
#if (%key=sedumrosea) {herb=sedum}
#if ((%key!=linguacanis) AND (%key!=virgapastoris) AND (%key!=sedumrosea)) {herb=%key}
#math mixpower (@mixpower+%val)
#var final %additem( get @herb @herbbag, @final)
#var herblist %additem( @herb, @herblist)
#math remainder (@max-@mixpower)
#if (@MixMin.@mixtype<=@mixpower<=@MixMax.@mixtype) {
#execute %expandlist( @final, ";")
#loop @mixnum {mix %expandlist( @herblist, " ")}
}
}
}
|
They keys in SprigPower, SprigCount, and SprigCheck are all identical, the values are all different though. @max is set by an outside alias.
What I'm trying to accomplish is:
1.Check to see that the sprigs power is less than or equal to the remainder, and verify that I actually have that sprig and enough to meet @mixnum
2.Some sprigs have 2 word names, hence the space removal in the first trig and the redefinition in the 2nd script. One word is assigned to @herb, which is added to a string list (@herblist).
3.Once power of the herbs I have selected matches the set range for the type of mixture I want, the stringlists holding the commands to get the sprigs from my bags and the appropriate sprig types are expanded and executed.
Is this sort of comparison possible, or feasible? I know its rough, and the loop structures aren't going to work properly, but I'm beginning to think this script will be too slow in its execution to work properly anyway. Is there a better way to compare lists? |
|
|
|
inimical Beginner
Joined: 12 Aug 2003 Posts: 14
|
Posted: Tue Aug 12, 2003 5:51 am |
I was running the first loop in debug and noticed that its looping each individual record 17 times in both variables. 2 vars, 18 values in each, 17 loops on each one, thats 612 loops! I cannot explain why that should be happening...
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue Aug 12, 2003 7:37 pm |
To start with, you don't need @SprigCheck. You can use the numbers from @Sprigcount instead. Also, since it appears your multi-word sprigs can all be identified from the first word you can further simplify by simply using that as your key.
I assumed the second script was all supposed to be part of the alias. The way you posted it, the alias just sets two variables.
You're running a #LOOP inside your #LOOPDB. This appears to be unintentional, since it looks like you want to go through the entire herblist before you begin mixing. I moved it outside and changed it to #REPEAT. I made numerous other changes either to simplify or simply to suit my own preferences. [:p]
If you decide to use this, be sure to change the keys in @SprigCount and @SprigPower (first word in the sprig's name).
#TR {(%d)~) a sprig of (%w)} {
#IF %iskey(@SprigCount, %2) {#ADDK SprigCount %2 %1}
}
#AL herb {
#VAR mixnum %1
#VAR mixtype %2
#VAR mixpower 0
#VAR remainder @max
#LOOPDB @SprigPower {
#IF ((%val <= @remainder) AND (@SprigCount.%key >= @mixnum)) {
#ADD mixpower %val
#ADDI final {get %key @herbbag}
#ADDI herblist %key
#ADD remainder -%val
}}
#IF ((@MixMin.@mixtype <= @mixpower) AND (@mixpower <= @MixMax.@mixtype)) {
#REPEAT @mixnum {
#EXEC %expandlist( @final, ";")
mix %expandlist( @herblist, " ")
}}} |
|
|
|
inimical Beginner
Joined: 12 Aug 2003 Posts: 14
|
Posted: Wed Aug 13, 2003 8:30 am |
Thanks, thats much better, but there's a glitch. In the first conditional the %key of SprigCount is the name of the herb, not the number of herbs, which is the value. Calling %val there would return the %val for SprigPower wouldn't it? Not sure how to fix that without resorting to a big cumbersome list of single variables for each value in count...
|
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Aug 13, 2003 3:34 pm |
The %key is from SprigPower, not SprigCount. The glitch is in @varname.key, the shortcut form of %db. The fix is to use %db.
Replace
#IF ((%val <= @remainder) AND (@SprigCount.%key >= @mixnum)) {
with
#IF ((%val <= @remainder) AND (%db( @SprigCount, %key) >= @mixnum)) { |
|
|
|
inimical Beginner
Joined: 12 Aug 2003 Posts: 14
|
Posted: Thu Aug 14, 2003 1:31 am |
Code: |
#AL herb {
mixnum=%1
mixtype=%2
#IF %iskey( @MixMax, @mixtype) {#VAR remainder @MixMax.@mixtype}
#LOOPDB @SprigCount {
#VAR SprigCount.%key {0}
}
look in @herbbag
#VAR mixpower 0
#LOOPDB @SprigPower {
#IF ((%val <= @remainder) AND (%db( @SprigCount, %key) >= @mixnum)) {
#ADD mixpower %val
#ADDI final {get %key @herbbag}
#ADDI herblist %key
#ADD remainder -%val
}}
#IF ((@MixMin.@mixtype <= @mixpower) AND (@mixpower <= @MixMax.@mixtype)) {
#REPEAT @mixnum {
#EXEC %expandlist( @final, ";")
mix %expandlist( @herblist, " ")
}}
|
This is what it looks like, and it seems to work, but after running it a couple of times zmud slowed waaaay way down. I rebooted several times, used settings files that didn't contain that alias, tried disabling it, nothing worked. Now all of the processes are super slow, and its basically impossible to even play due to the huge lag zmud is giving me. I'm using a 3ghz Pent 4 with 512mb ram, so I really don't think my memory should be so totally consumed. I don't know why rebooting didn't clear it up, but I think zmud's memory allocation must be terrible when it comes to dbs. Anyone else have this problem? |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Thu Aug 14, 2003 3:45 am |
From what you say, you first noticed zMUD slowing down while you were using this alias. But you then go on to say that it REMAINED slow even after rebooting and using settings files which DON'T contain this alias. Nonetheless, you seem to think that it's this alias which is at fault. That seems extremely unlikely.
This alias doesn't contain anything which should make zMUD particularly slow. If it did, any slowdown it caused would end when the alias reached its end. It would certainly end when you rebooted the computer. Nor is there any capability for any zMUD setting to load itself into memory without being included in one of the settings files zMUD loads for a character. It's far more likely that something else is the cause of the slowdown, and it's just coincidence that this alias happened to be running when you noticed it.
On a side note, you don't need your first loop
#LOOPDB @SprigCount {#VAR SprigCount.%key {0}}
since you already know the names of all your herbs. Just set them to 0 in a direct statement.
#ADDKEY SprigCount {lingua|virga|sedum} 0
(those are the only three names you've allowed to slip out) |
|
|
|
inimical Beginner
Joined: 12 Aug 2003 Posts: 14
|
Posted: Thu Aug 14, 2003 4:42 am |
You're right of course, I don't know what the cause of it is but maybe reinstalling will clear it up. Thanks for all the help Lightbulb, you're a zmud jedi in my book
|
|
|
|
inimical Beginner
Joined: 12 Aug 2003 Posts: 14
|
Posted: Thu Aug 14, 2003 6:06 am |
And I spoke too soon about the whole "it works" thing [:p]
#VAR remainder {@MixMax.@mixtype} isnt working properly, because mixmax expands first and sets remainder to be a data record with the same values as mixmax with only the text held by mixtype stuck in at the end. I think if @mixtype expanded first it would work perfectly. Its pretty likely the other occurences of @variable.@othervariable will do the same thing.
Help me obi wan, you're my only hope :> |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Thu Aug 14, 2003 7:45 am |
%db( @MixMax, @mixtype)
|
|
|
|
inimical Beginner
Joined: 12 Aug 2003 Posts: 14
|
Posted: Thu Aug 14, 2003 1:15 pm |
This is the script that refuses to work, for every problem solved a new one arises. Now I've noticed an issue with this piece
(%db( @SprigCount, %key)
within the #loopdb command. It returns nothing. I tested it from every angle I could think of and it just doesnt return a thing. I don't know if its because its a db inside a db or what, but if you've got another shot at this one Mr. Wizard I'd be grateful. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Thu Aug 14, 2003 2:49 pm |
Actually it's %db( @SprigCount, %key). Or, it could be (%db( @SprigCount, %key) >= @mixnum).
I don't know how you tested it. I tested it by putting numbers into @remainder and @mixnum, and name-number pairs into @SprigPower and @SprigCount, then running a #LOOPDB which gave me different responses for true and false. It works fine. |
|
|
|
|
|
|
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
|
|