Jump to content
Sign in to follow this  
Mars

How to carry variables over from a function

Recommended Posts

Mars

How do you make it so that you can use the variables and their values that were declared in a func outside of that function?

Share this post


Link to post
Share on other sites
Authenticity

Using the Global keyword as opposed to Local or Dim.

Share this post


Link to post
Share on other sites
Mars

I haven't been declaring them of any type so I'm guessing you just put global before the variable?

Share this post


Link to post
Share on other sites
Authenticity

Yes, otherwise, local is assumed. I think.

Share this post


Link to post
Share on other sites
SmOke_N

Yes, otherwise, local is assumed. I think.

Local is only assumed if the variable is declared within a function (or used in a For/Next eg. For $i where $i would be declared local unless otherwise stated previously, if declared this way, it will be destroyed like a Local variable after the For/Next loop expires).

Example of standard global distinction:

$s_example1 = "apple"
_badwaytodoit()

Func _badwaytodoit()
    MsgBox(64, "$s_example1", $s_example1)
EndFuncoÝ÷ ØÚ-uç%j¸§*.®ö«¦å{ûr¥ë"²Ø^²Ö«¶ÛiØZn+l~ߺ۫yÊx×¾ìb·öYl¢å¢Ç¬×¨Z·*.Á©í¶Þj  hm©oj¸nW¨­©hq©oj¸nW¢g­)ත¬ zܨº)íèZn+h}תâazgâ®Ëp¢é]mëh¦ëZºÚ"µÍÜ
    ][ÝÓ]ÝXÛUÉ][ÝËJ
At the top of your scripts. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Mars

Okay that worked thanks. I learned autoit through playing around with it but right now I am in C++ classes and I will probably get in the habit of declaring variable types from now on.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×