| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Tue May 13, 2008 5:10 pm Post subject: The use of Global |
|
|
Can You have the "Global-definition" in the begining of the script
or
Do You must have it inside the function?
Ex 1 - in the begining
Global var1
Var1 = ........
Function1
ExitApp
Function1()
(
...... Var1 + ......
)
Ex 2 - in the Functions
Var1 = .....
Function1
ExitApp
Function1()
(
Global var1
...... Var1 + ......
) |
|
| Back to top |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 363
|
Posted: Tue May 13, 2008 8:35 pm Post subject: |
|
|
Anything outside of a function is in the main scope. Once inside a function, you are inside the function's scope. You use global in a function to access variables in the main scope. This should be a good example to show you how it works: | Code: | var1 = global scope
var2 = global scope
func1()
return
func1()
{
global var1
msgbox, func1`nvar1=%var1%`nvar2=%var2%
var1 .= "-func1"
var2 .= "-func1"
msgbox, func1`nvar1=%var1%`nvar2=%var2%
func2()
}
func2()
{
global var1, var2
msgbox, func2`nvar1=%var1%`nvar2=%var2%
} |
|
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 14, 2008 9:28 am Post subject: |
|
|
Thank´s
Why do You use "Return" and not ExitApp in the end of the mainscript?
Do You need anything in the end of the mainscript? |
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 14, 2008 9:57 am Post subject: |
|
|
| ?? |
|
| Back to top |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 363
|
Posted: Wed May 14, 2008 1:49 pm Post subject: |
|
|
Force of habit carried over from other languages.
| Return wrote: | | If there is no caller to which to return, Return will do an Exit instead. |
|
|
| Back to top |
|
 |
|