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


Joined: 06 Apr 2004
Posts: 173

PostPosted: Tue Jan 25, 2005 5:08 am   

Scope of variables in recurrsive calls
 
Id like to make some recursive functions similar to the example in the section #HELP FUNCTION, but im worried about using variables in the function because they seem to be very global in nature. Unfortunately the function im designing needs to use some form of temporary variable.

Is there a way do declare the scope of a variable to local, rather than global, so the variable cannot be seen outside of a function? or have the ability to destroy the recurrsion by accidentially overwriting data from a previous call...

In addition i was wondering about the use of the #LOOP command's %i variable...is it safe in a recurrsive call....

thanks,
Graham
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Jan 26, 2005 12:43 am   
 
Nope, there is no form of scope used in ZScript among user-created variables, other than location (ie, ZMud will use the first-found instance if you don't provide specific location). Location-based scope only applies to the use of the setting, not the contents thereof:

(NONE)
alias
alias
Variable1 = 25
Variable1 = 15

#SHOW @Variable1 would always output 25, unless for some reason variables could be disabled (in which case, if the first Variable1 was disabled the #Show would show 15). This applies to all types of settings, but in the case of triggers every enabled trigger is tested against the line rather than just the first one.
_________________
EDIT: I didn't like my old signature
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Jan 26, 2005 11:00 am   
 
Perhaps if you tell us what your looking to do we can devise another way. In general programming recursive function are rarely necessary and while very powerful they are often avoided. There is almost always another way.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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