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


Joined: 26 Sep 2002
Posts: 8

PostPosted: Wed Oct 23, 2002 5:18 pm   

Trigger output problem
 
You guys just always seem to be able to fix my problems so I keep coming back! *grin*
My latest problem is with an expression trigger. I have a variable wich holds a bunch of commands to do, a queue basically. Each command has a priority. I search through the priorities and execute the lowest number. Somehow, the output is all messed up. Here's my code which might be much easier to understand than my ramblings...hehe

#TRIGGER (%numitems(@varSalveQueue) > 0 AND (@varBalance = 1) AND (@varStunned = 0) AND (@varSleeping = 0) AND (@varStupidity = 0)) {#LOOP %numwords( {@varSalveQueue}, "|") {varCurrentSNum = %number( %left( %word( {@varSalveQueue}, 3)), %i, ", ");#IF (@varCurrentSNum < @varLowestSNum) {varLowestSNum = @varCurrentSNum};varLowestSalve = (%right( %word( {@varSalveQueue}, 4)));varLowestFull = %word( {@varSalveQueue})};#EXEC @varLowestSalve;%delitem( @varSalveQueue, @varLowestFull);#SHOW Queue: @varSalveQueue;#SHOW Lowest Num: @varLowestSNum;#SHOW Lowest Salve: @varLowestSalve;#SHOW Full: @varLowestFull}

And here is the output from the #SHOW commands I use for debugging:

Queue: 203 apply restoration to legs|212 apply mending to legs|203 apply restoration to legs|212 apply mending to legs|203 apply restoration to legs|203 apply restoration to legs|212 apply mending to legs|
Lowest Num: 0
Lowest Salve: (to)
Full:

So the trigger is firing when it should, but the output is all messed up. Anyone have any clue where I am going wrong? Thanks!
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Oct 23, 2002 7:23 pm   
 
Based on the output of your #SHOW commands, you have the following variables:
@varSalveQueue: {203 apply restoration to legs|212 apply mending to legs|203 apply restoration to legs|212 apply mending to legs|203 apply restoration to legs|203 apply restoration to legs|212 apply mending to legs| }
@varLowestSNum: {0}
@varLowestSalve: {(to)}
@varLowestFull: {}

Trigger analysis, based on above variables and assuming the expression is true:
#LOOP %numwords( {@varSalveQueue}, "|")
- #LOOP 8

Final loop:
varCurrentSNum = %number( %left( %word( {@varSalveQueue}, 3)), %i, ", ")
- varCurrentSNum = %number( %left( "restoration"), 8, ", ")
-- varCurrentSNum = %number( "", 8, ", ")
--- varCurrentSNum = 0

#IF (@varCurrentSNum < @varLowestSNum)
- #IF (0 < 0)
-- *NOTE* @varLowestSNum hasn't been defined yet, but can be assumed to be 0 from previous use of the trigger
--- False, so use false commands (there aren't any)

varLowestSalve = (%right( %word( {@varSalveQueue}, 4)))
- varLowestSalve = (%right( "to"))
-- varLowestSalve = ("to")
--- varLowestSalve = (to)

varLowestFull = %word( {@varSalveQueue})
- varLowestFull = %word( @varSalveQueue, 0, " "}
-- varLowestFull = ""
*END OF LOOP*

#EXEC @varLowestSalve
- (to)
-- *NOTE* sent to MUD

%delitem( @varSalveQueue, @varLowestFull)
- %delitem( {203 apply restoration to legs|212 apply mending to legs|203 apply restoration to legs|212 apply mending to legs|203 apply restoration to legs|203 apply restoration to legs|212 apply mending to legs| }, }
-- *NOTE* this returns the value of @varSalveQueue with nothing deleted, but it wouldn't delete anything anyway. You either have to assign the result to a variable or use #DELITEM

Followed by a series of #SHOW, the output of which you've already seen. It does exactly what you told it to.

Basically, you've messed up on the functions -- you almost never provide the correct number of parameters for the function. Much of the problem is that you're using string functions with an item list, when list functions would probably be more appropriate.

LightBulb
Senior Member
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Oct 23, 2002 10:21 pm   
 
Lightbulb's analysis was quite right.
As he points out varLowestSNum was defined to a high number at the start so norhing was ever happening there. Also your script was set to only store the extracted snum after the comparison and keep updating the salve data with each pass of the loop, this would have caused you to execute the wrong salve at least half the time. The final item of concern was that you did not affect any of the variables in such a fashion that the trigger would become disabled, so I added that as well.

Otherwise just some cosmetic changes improving speed, readability and the size of the script.

#TRIGGER ((%numitems(@varSalveQueue) > 0) AND (@varBalance = 1) AND (@varStunned = 0) AND (@varSleeping = 0) AND (@varStupidity = 0)) {LowestSNum=1000;#FORALL @varSalveQueue {varCurrentSNum = %word( %i, 1);#IF (@varCurrentSNum < @varLowestSNum) {varLowestSNum = @varCurrentSNum;varLowestSalve = %trim(%remove(%word(%i,1),%i));varLowestFull = %i}};#EXEC @varLowestSalve;#DELITEM varSalveQueue {@varLowestFull};varBalance=0;#SHOW Queue: @varSalveQueue;#SHOW Lowest Num: @varLowestSNum;#SHOW Lowest Salve: @varLowestSalve;#SHOW Full: @varLowestFull}
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