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 

About functions

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Matis
Guest





PostPosted: Sun Mar 01, 2009 8:26 pm    Post subject: About functions Reply with quote

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. Smile
Back to top
BoBoł
Guest





PostPosted: Sun Mar 01, 2009 8:41 pm    Post subject: Reply with quote

Code:
answer := add(2, 2)
msgbox, %answer%

Add(x, y)
{
   Return (x+y)
   }
Back to top
BoBoł
Guest





PostPosted: Sun Mar 01, 2009 8:44 pm    Post subject: Reply with quote

Code:
MsgBox % add(10, 2)
Add(x, y) {
   Return (x+y)
   }
Shorter.
Back to top
Jex



Joined: 01 Aug 2008
Posts: 101

PostPosted: Sun Mar 01, 2009 8:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
Guest






PostPosted: Sun Mar 01, 2009 8:57 pm    Post subject: Reply with quote

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 Smile Thanks. My function have about 20 variables, can't make everything "return"
Back to top
Display posts from previous:   
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