Jump to content
Sign in to follow this  
Guest

A basic problem in AutoIt3

Recommended Posts

Guest

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

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
Guest

why the:

$value = _test()

_func1()

?

Share this post


Link to post
Share on other sites
Guest

Ok

Possible to do it with the Call() ?

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
Guest

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

$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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...