Sign in to follow this  
Followers 0
gil900

A basic problem in AutoIt3

9 posts in this topic

Not much to say ..

To save words simply try to run this code:

call("test")

Func test()
$test = "working"
Call("func1")
EndFunc

Func func1()
MsgBox(4096,"test",$test)
EndFunc

The variable $test is not saved if it is in the function.

This basic problem prevents me from continuing to program what I want.

I have the variable will remain even after the exit from the function ..

I do not understand why the system works that way ..

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You need to Return the variable if you want it available outside of the function.

$value = _test()
_func1()

Func _test()
$test = "working"
Return $test
EndFunc

Func _func1()
MsgBox(4096,"test", $value)
EndFunc
Edited by kor

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Because that's the way you run functions.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Yes. But with call you are limited. You can't use ByRef which for me personally is a deal breaker.

I would learn to call functions the way everyone else does though. it will make getting help on the forums much easier.

I've never seen anyone use the Call before.

Share this post


Link to post
Share on other sites

Why add another variable?

It also works:

$test = test()
Call("func1")

Func test()
$test = "working"
Return $test
EndFunc

Func func1()
MsgBox(4096,"test", $test)
EndFunc

It's only with one variable.

There is another situation that I have to show.

Share this post


Link to post
Share on other sites

this is the new problem:

$a = test()

$v1 = 5
$v2 = 10

for $i = 1 to $v1 step 1
test()
Next

Func test()
for $o = 1 to $v2 step 1
$a = $o
Return $a
test2()
Next
EndFunc

func test2()
for $q = 1 to 20 step 1
msgbox(4096,"working",$a)
Next
EndFunc

I tried what you said but in this case it did not work

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

$a = test() ;$a will equal the first thing test returns

$v1 = 5
$v2 = 10

for $i = 1 to $v1 step 1
test()
Next

Func test()
for $o = 1 to $v2 step 1
$a = $o
Return $a ;the function returns the value $a is currently set to in this case the loop is pointless and will always return the number 1
test2() ;this never executes
Next
EndFunc

func test2()
for $q = 1 to 20 step 1
msgbox(4096,"working",$a)
Next

Edited by Deltron0

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  
Followers 0