AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Variables in functions - Dont know how to solve this

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Zöman
Guest





PostPosted: Thu Nov 08, 2007 11:38 pm    Post subject: Variables in functions - Dont know how to solve this Reply with quote

I have split up a lot of code in a number of functions. There is one mother function and several child functions. I want all the variables to be accessible to all functions in this cluster, but I want them to be inaccessible to other parts of the applications, and I want them to become garbage collected every time the application finishes using this cluster.

In other words, I want variables to be global to each other within a cluster of function and global to the rest of the code.

Is this explicitly doable? Can it be solved somehow?
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Fri Nov 09, 2007 12:37 am    Post subject: Reply with quote

I think probably not easily. you could maybe have a seperate ahk file running, which would get garbage collected when it's closed.

Not pretty, but could work.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Fri Nov 09, 2007 2:04 am    Post subject: Re: Variables in functions - Dont know how to solve this Reply with quote

Zöman wrote:
I have split up a lot of code in a number of functions. There is one mother function and several child functions. I want all the variables to be accessible to all functions in this cluster, but I want them to be inaccessible to other parts of the applications, and I want them to become garbage collected every time the application finishes using this cluster.

In other words, I want variables to be global to each other within a cluster of function and global to the rest of the code.

Is this explicitly doable? Can it be solved somehow?

No. However the best alternative is to pass the variables ByRef between functions. Then any changes to that variable by a child function will be seen by the mother function.

Example:
Code:
MotherFunction() {
   local var1, var2, var3
   ChildFunction1(var1)
   ChildFunction2(var2, var3)
   MsgBox, %var1% %var2% %var3%
}
ChildFunction1(ByRef par1) {
   par1 := "a"
}
ChildFunction2(ByREf par1, ByRef par2) {
   par1 := "b"
   par2 := "c"
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group