 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Matis Guest
|
Posted: Sun Mar 01, 2009 8:26 pm Post subject: About functions |
|
|
Hi. I have little problem in functions with ahk. In e.x i want to make function to store var data and be accesible on main script.
I.E:
| Code: | add(2, 2)
msgbox, %answer%
Add(x, y)
{
answer := x + y
} |
After this answer is still blank, i want that answer would be = 4.  |
|
| Back to top |
|
 |
BoBoł Guest
|
Posted: Sun Mar 01, 2009 8:41 pm Post subject: |
|
|
| Code: | answer := add(2, 2)
msgbox, %answer%
Add(x, y)
{
Return (x+y)
} |
|
|
| Back to top |
|
 |
BoBoł Guest
|
Posted: Sun Mar 01, 2009 8:44 pm Post subject: |
|
|
| Code: | MsgBox % add(10, 2)
Add(x, y) {
Return (x+y)
} | Shorter. |
|
| Back to top |
|
 |
Jex
Joined: 01 Aug 2008 Posts: 101
|
Posted: Sun Mar 01, 2009 8:44 pm Post subject: |
|
|
the variable answer isn't global, meaning the variable doesn't exist out side of the function.
One option:
| Code: | msgbox, % add(2,2)
Add(x, y)
{
return x+y
} |
Or you could make the variable global
| Code: | add(2,2)
msgbox, %answer%
Add(2,2)
{
Global answer
answer := x+y
} |
_________________ Woot.
Please read forum etiquette |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Mar 01, 2009 8:57 pm Post subject: |
|
|
| Jex wrote: | the variable answer isn't global, meaning the variable doesn't exist out side of the function.
One option:
| Code: | msgbox, % add(2,2)
Add(x, y)
{
return x+y
} |
Or you could make the variable global
| Code: | add(2,2)
msgbox, %answer%
Add(2,2)
{
Global answer
answer := x+y
} |
|
Yes Global. This is what i need Thanks. My function have about 20 variables, can't make everything "return" |
|
| 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
|