Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Sat Sep 29, 2007 6:08 am   

[2.04] $local #loop
 
#LOOP 25 {#ADD $test 1;#SAY $test}

The value of $test is always 1.

Shouldn't it increment itself since it is completely within the loop?
_________________
Discord: Shalimarwildcat
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Sep 29, 2007 8:30 am   
 
I think this is the way it's supposed to be. Since $test is defined with the scope of the loop ( and only withing that scope ) it is essentially reset with every iteration. It is the same as declaring a variable with a 'while' in C/C++/Java, it's redefined at the start of each loop iteration and destroyed at the end of each loop iteration. You need a variable outside of the loop to do what you want.
_________________
Asati di tempari!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Sep 29, 2007 1:27 pm   
 
Tech is correct.

#local $test
#loop 25 {#add $test 1;#say $test}

gives you the result you're looking for.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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