 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Zöman Guest
|
Posted: Thu Nov 08, 2007 11:38 pm Post subject: Variables in functions - Dont know how to solve this |
|
|
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
|
Posted: Fri Nov 09, 2007 12:37 am Post subject: |
|
|
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 |
|
 |
Xander
Joined: 23 Sep 2007 Posts: 142
|
Posted: Fri Nov 09, 2007 2:04 am Post subject: Re: Variables in functions - Dont know how to solve this |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|