return multiple vars from an #include script ?
return multiple vars from an #include script ?
From a function that runs in a separate script (as #include)
I should return about 6 VAR values to the main script.
How do I do that?
James
I should return about 6 VAR values to the main script.
How do I do that?
James
Re: return multiple vars from an #include script ?
It requires no special handling because the included code acts as if it existed in the main script itself. Thus, the scripts do not behave as separate scripts, but as one.
#Include:
#Include:
How to confirm: run your script.Causes the script to behave as though the specified file's contents are present at this exact position.
Doesn't work..
This is (part of) the main script.
It calls a routine : get_yValues()
That routine changes thouse testVar[1-6]
but in the main script, these changes doesn't show.
The Main script:
The included script (with the get_yValues() function)
It calls a routine : get_yValues()
That routine changes thouse testVar[1-6]
but in the main script, these changes doesn't show.
The Main script:
Code: Select all
Yellow_chk:
testVar1:=999
testVar2:=888
testVar3:=777
testVar4:=666
testVar5:=555
testVar6:=444
get_yValues()
msgbox, 0,, Results from the the function: %testVar1%`, %testVar2%`, %testVar3%`, %testVar4%`, %testVar5%`, %testVar6%, 90
return
Code: Select all
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
get_yValues()
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
{
xyFound:=-1
while xyFound<1
{
; send, !+W ;Call the yWatcher window
soundPlay, %A_WorkingDir%\Sounds\cycle.wav, 1
testVar1:=1.11
testVar2:=2.12
testVar3:=3.13
testVar4:=4.14
testVar5:=5.15
testVar6:=6.16
xyFound:=1
return (testVar1, testVar2, testVar3, testVar4, testVar5, testVar6)
}
Re: return multiple vars from an #include script ?
Without checking anything else about your script. You have a variable scope problem. The function doesn’t see the variables outside the function, and the code outside the function can’t see the ones inside it. The quickest fix is to declare them as global inside your function or super-global (can be seen by any function) by declaring them as global outside your function.
Re: 'variable scope' ??!
I started reading about 'variable scope' and it's quite a lot to read..
I do not have that much time for it and I am looking for a quick fix. Is there any definition I should apply for the system to detect variables that should be visible in both scripts?
I learned to use ByRef and it works for me.
I'm wondering whether if there's any limitation using this ByRef definition?!
maybe it's affecting speed or has some other downside that effect the scripts?
I'd be happy to get more info about the issue.
Thanks
James
I do not have that much time for it and I am looking for a quick fix. Is there any definition I should apply for the system to detect variables that should be visible in both scripts?
I learned to use ByRef and it works for me.
I'm wondering whether if there's any limitation using this ByRef definition?!
maybe it's affecting speed or has some other downside that effect the scripts?
I'd be happy to get more info about the issue.
Thanks
James
Re: 'variable scope' ??!
Hmm...maybe you found my four-sentence post to be quite a lot to read as well and didn't make it to this part of it:
No real limitations. To help you learn more, I would just be pointing you to the documentation. It would require some more reading, and since you say you don't have that much time for it, I won't take my own time to cite the locations in the documentation.
Dear Sir, I apologize.
By saying "I do not have time to read" I did not meant to the four lines in your previous answer, but to the 232 lines explaining the value 'variable scope'.
I am sorry that you got offended from me.
I didn't meant to disrespect you nor your explanations.
I apologize to you.
In spite of my busy schedule, I found the time and read about the easy solution that you mentioned in your answer.
I still don't fully understand the other options that are available to handle the issue without the need for global variables, but for now, 'global' and 'ByRef' are enough for me at this point.
You helped me a lot,
Thank you,
James
I am sorry that you got offended from me.
I didn't meant to disrespect you nor your explanations.
I apologize to you.
In spite of my busy schedule, I found the time and read about the easy solution that you mentioned in your answer.
I still don't fully understand the other options that are available to handle the issue without the need for global variables, but for now, 'global' and 'ByRef' are enough for me at this point.
You helped me a lot,
Thank you,
James
Re: return multiple vars from an #include script ?
I appreciate your comments. My view is that the help given in this forum should be seen as a supplement to the documentation, not a replacement for it. If someone says they've read the documentation but didn't understand something about it or couldn't apply it correctly, then I'll try to help. If someone says "I don't have time to read it so please take your time to tell me what it says," I won't do that.