Guest Posted August 12, 2012 Share Posted August 12, 2012 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 .. Link to comment Share on other sites More sharing options...
kor Posted August 12, 2012 Share Posted August 12, 2012 (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 August 12, 2012 by kor Link to comment Share on other sites More sharing options...
Guest Posted August 12, 2012 Share Posted August 12, 2012 why the: $value = _test() _func1() ? Link to comment Share on other sites More sharing options...
kor Posted August 12, 2012 Share Posted August 12, 2012 Because that's the way you run functions. Link to comment Share on other sites More sharing options...
Guest Posted August 12, 2012 Share Posted August 12, 2012 Ok Possible to do it with the Call() ? Link to comment Share on other sites More sharing options...
kor Posted August 12, 2012 Share Posted August 12, 2012 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. Link to comment Share on other sites More sharing options...
Guest Posted August 12, 2012 Share Posted August 12, 2012 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. Link to comment Share on other sites More sharing options...
Guest Posted August 12, 2012 Share Posted August 12, 2012 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 Link to comment Share on other sites More sharing options...
Deltron0 Posted August 12, 2012 Share Posted August 12, 2012 (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 August 12, 2012 by Deltron0 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now