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
Turbomudder
Beginner


Joined: 25 Jan 2003
Posts: 19

PostPosted: Sun Jan 26, 2003 11:46 am   

problem possibly caused by long loop
 
I am trying to run the following alias
#VAR potionnum %1
#LOOP 1,%numitems(@numberlist) {#VAR ingrednum %item(@numberlist,%{i})
#VAR turn 1
#WHILE (@turn <= 20) {#IF (%copy(@potionnum,@turn,1) = "0" & %copy(@ingrednum,@turn,1) != "0") {#IF (%ismember(@ingrednum,@numberlist) >= 1) {#DELNITEM invbasket %ismember(@ingrednum,@numberlist)}
#VAR numberlist %delitem(@ingrednum,@numberlist)
#VAR turn 21} {#MATH turn @turn+1}}}
#SH Done computing

out of context that might be a bit hard to follow, but... the numbers im dealing with at in binary with 20 places, so what im doing is removing all the numbers that have 1's where there are 0's in the "potionnum"

the really wierd thing is, it all seems to work fine, if i repeat this whole sequence 4 or five times, the list gets shorter and shorter until eventually it has eliminated all the proper numbers and then if i repeat the script, the list doesnt change...
so my question is, why doesnt it eliminate all of them the first time around? could it be that the 150 or so items in "numberlist" is to many times to repeat that loop without getting some bug.? whats the deal?

thanks,
turbomudder
Reply with quote
Turbomudder
Beginner


Joined: 25 Jan 2003
Posts: 19

PostPosted: Sun Jan 26, 2003 12:33 pm   
 
Welp, I figured it out...
whenever it would delete an item from the list, that slid everything down a notch, so when it tried to use %i for the item number in the string "numberlist" it was off by however many items it had already deleted...
I added a line to subtract 1 from the %i value when it deleted something and now it works fine...
if nothing else maybe this has been a good example for others, anyway heres the way it looks when it works properly:

#VAR potionnum %1
#VAR subval 0
#MATH looptimes %numitems(@numberlist)+1
#LOOP 1,@looptimes {#MATH slotnum %{i}-@subval
#VAR ingrednum %item(@numberlist,@slotnum)
#VAR turn 1
#WHILE (@turn <= 20) {#IF (%copy(@potionnum,@turn,1) = "0" & %copy(@ingrednum,@turn,1) != "0") {#IF (%ismember(@ingrednum,@numberlist) >= 1) {#DELNITEM invbasket %ismember(@ingrednum,@numberlist)}
#VAR numberlist %delitem(@ingrednum,@numberlist)
#MATH subval @subval+1
#VAR turn 21} {#MATH turn @turn+1}}}
#SH Done computing

Turbomudder
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