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
user0101
Apprentice


Joined: 01 Aug 2003
Posts: 100
Location: USA

PostPosted: Tue Aug 05, 2003 5:34 am   

Imbedded Triggers
 
Are there any more efficient ways to run a checklist and still have priority?

#if (@mostimportantvar=1) {var1action}
#if (@mostimportantvar=0) {#if (@secondmostimportantvar=1) {var2action}}

Imbedding triggers in this manner seems fine when you only need to run priority checks on a few things, but what about long lists? There has to be a more efficient way to code it which I'm not aware of. (I've searched for any threads relating to this, and read all the help files without any luck)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Aug 05, 2003 11:23 am   
 
#CASE
Reply with quote
user0101
Apprentice


Joined: 01 Aug 2003
Posts: 100
Location: USA

PostPosted: Tue Aug 05, 2003 2:45 pm   
 
I know I've been bugging everyone with my questions but I honestly tried to figure it out myself and find the answer. No luck, so here goes. (I researched all threads with #CASE in them Vijilante, most only mentioned #CASE as a solution, but never laid out a framework for using it as a primary means of optomization)

I need to optomize this:

#if (@balherb=0) {#if (@ginseng=1) {egi}}
#if (@balherb=0) {#if (@ginseng=0) {#if (@bloodroot=1) {ebl}}}
#if (@balherb=0) {#if (@ginseng=0) {#if (@bloodroot=0) {#if (@goldenseal=1) {ego}}}}
#if (@balherb=0) {#if (@ginseng=0) {#if (@bloodroot=0) {#if (@goldenseal=0) {#if (@bellwort=1) {ebe}}}}}
#if (@balherb=0) {#if (@ginseng=0) {#if (@bloodroot=0) {#if (@goldenseal=0) {#if (@bellwort=0) {#if (@lobelia=1) {elo}}}}}}
#if (@balherb=0) {#if (@ginseng=0) {#if (@bloodroot=0) {#if (@goldenseal=0) {#if (@bellwort=0) {#if (@lobelia=0) {#if (@ash=1) {eas}}}}}}}
#if (@balherb=0) {#if (@ginseng=0) {#if (@bloodroot=0) {#if (@goldenseal=0) {#if (@bellwort=0) {#if (@lobelia=0) {#if (@ash=0) {#if (@kelp=1) {eke}}}}}}}}

This is just a portion of it.. With upwards of 30+ lines of this it can really start to slow down.
Reply with quote
Rehcra
Novice


Joined: 10 Oct 2000
Posts: 43

PostPosted: Tue Aug 05, 2003 5:25 pm   
 
Not the most elegant solution, but...

#IF has a True and a False command. You are only using the True part

Syntax:

#IF expression true-command [false-command]
%if(expression,true-value,false-value)

So the first 3 lines could become:

#if (@balherb=0) {%if(@ginseng=1,egi,%if(@bloodroot=1,ebl,%if(@bellwort=1,ebe)))}

You shouldn't ever have to retest a variable. This will cut out the majority of your IF's.

I'd have to brain storm a bit for a more elegant solution.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue Aug 05, 2003 10:28 pm   
 
I'd recommend redoing your system to use a single variable to represent which herbs are needed. This can be done using a string of 0's and 1's, with 1 when the herb is needed and 0 when it's not.

Thus, for your first seven herbs you have ginseng, bloodroot, goldenseal, bellwort, lobelia, ash, and kelp. So, the first digit will represent ginseng, the second will represent bloodroot, and likewise until the seventh which represents kelp. The problem now comes down to how to change the value of a single digit, and how to find the first 1.

The first problem can be solved by using %left and %right.
#VAR herbs {0111010} // Example indicating you need to eat bloodroot, goldenseal, bellwort, and ash
#AL ChangeBellwort {#VAR herbs %left( @herbs, 3)%1%right( @herbs, 4)} // I expect you to be smart enough to always supply a %1 which is either 0 or 1

The second problem is even easier, since it just requires using %pos.
#IF ((@balherb = 0) AND %pos( 1, @herbs)) {#CASE %pos( 1, @herbs) {egi} {ebl} {ego} {ebe} {elo} {eas} {eke}}
Reply with quote
user0101
Apprentice


Joined: 01 Aug 2003
Posts: 100
Location: USA

PostPosted: Wed Aug 06, 2003 9:19 am   
 
Let's say var1 equals 0000000. Using %left in conjuction with %right wraps the numbers. For example:
#AL ChangeDigit2 {#VAR var1 %left( @var1, 1)1%right( @var1, 2)}
Var1 now equals: 0100001

The others get set fine. Example:
#AL ChangeDigit6 {#VAR var1 %left( @var1, 5)1%right( @var1, 6)}
Var1 now equals: 0000010

What am I doing wrong?

Rehcra, yours works great but LightBulbs is probably the fastest, since it only uses 1 variable. Thanks though, any help is appreciated Smile
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Wed Aug 06, 2003 1:32 pm   
 
Instead of storing your variables in umpteen different variables store them in one db variable.

#VAR allherbs {balherb=0|ginseng=6|bloodroot=3|goldenseal=0|kelp=69}

#LOOPDB @allherbs {#IF (%val > 0) {use %key; #ADDKEY allherbs %key %eval(%val - 1); #ABORT 1}}

The record variable should maintain the order of the elements, thus preserving your priorities.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Aug 06, 2003 3:50 pm   
 
I can't see that you're doing anything wrong. I also can't get the wrap you describe. Your alias works fine for me. It would appear you made an earlier change to digit 7.
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