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: Wed Jan 29, 2003 11:43 am   

problem with #WHILE
 
Im trying to do this:
#VAR turn 1
#WHILE (@turn <= 20) {#IF (%copy(%i,@turn,1) = "1" & %copy(@combonum,@turn,1) = "0") {#VAR combonum %delete(@combonum,@turnandone,1)
#VAR combonum %insert(1,@combonum,@turn)}
#ADD turn 1}

the loop stops when its supposed to and when its done, the variable @turn is indeed 21 as it should be, however in all the places that it is used within the loop, the initial value, 1, is always inserted, even after it has been through several cycles so it should be a higher number...
I dont get it.
If you do i appreciate your input.

Thanks,
Turbomudder
Reply with quote
tbone235
Apprentice


Joined: 02 Nov 2002
Posts: 107
Location: Australia

PostPosted: Wed Jan 29, 2003 1:28 pm   
 
You say its always 1? I would be inclined to check this using a say command or something, because maybe the problem is not the turn variable but something inside your if statment maybe...

try putting in something like ..
#VAR turn 1
#WHILE (@turn <= 20) {#IF (%copy(%i,@turn,1) = "1" & %copy(@combonum,@turn,1) = "0") {#VAR combonum %delete(@combonum,@turnandone,1)
#VAR combonum %insert(1,@combonum,@turn)}
say @turn
#ADD turn 1}


and see what happens, because there seems to be nothing wrong with how you are increasing the variable, so IMO i think its somewhere in your other statments that the problem lies
Reply with quote
Turbomudder
Beginner


Joined: 25 Jan 2003
Posts: 19

PostPosted: Wed Jan 29, 2003 1:39 pm   
 
yep i tried using show already, it stays 1 through the whole loop until after it's completed the 20 turns.

Turbomudder.
Reply with quote
tbone235
Apprentice


Joined: 02 Nov 2002
Posts: 107
Location: Australia

PostPosted: Wed Jan 29, 2003 1:41 pm   
 
ok, i just copied and pasted the code i gave you into my mud and it went through all 20...so... I dunno what your doing, cause it said 1 throught 20 for me :P
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Wed Jan 29, 2003 1:46 pm   
 
How about a simpler loop:
#VAR turn 1
#WHILE (@turn <= 20) {#SH @turn}

Does that present the same problem? Also, you might want to check that in Expand Vars under Script Parser in the Preferences is not enabled.

Finally, although it would be best to find the problem, you should know that you can accomplish the same thing #LOOP (although you already have a %i in your script which I don't know where it comes from):
#LOOP 20 {#SH %i}

Kjata
Reply with quote
Turbomudder
Beginner


Joined: 25 Jan 2003
Posts: 19

PostPosted: Wed Jan 29, 2003 1:52 pm   
 
the %i is from a #forall which this script is within... the very simple #VAR turn 1;#WHILE (@turn <= 20) {#SH @turn;#ADD turn 1} did indeed have the same problem, until i turned off expand vars, and that solved it... thanks a lot, i would have never found that...
what does expand vars do anyway?

thanks again,
turbomudder
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Wed Jan 29, 2003 4:49 pm   
 
Expand vars is mostly used for when you want variables typed in the command line to be expanded without having to surround it with []'s to force expansion. However, enabling this option has a side effect (the one you saw), which is that when a script is executed, all variable references are expanded before executing any command in the script. Since @turn was being replaced by 1 before any command was executed, it didn't matter if you updated it's value, 1 would always be used in place of @turn everywhere it appeared.

Kjata
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