AhkThread() from inline code vs separate file

Ask for help, how to use AHK_H, etc.
User avatar
RazorHalo
Posts: 32
Joined: 21 Dec 2015, 21:23

AhkThread() from inline code vs separate file

17 Feb 2020, 21:35

Is there some difference for commands used on threads created with inline code vs separate script file?

In the examples functions like Alias() and CritialObject() work fine when using a thread created within the main script

Code: Select all

project1:={Key:"this is a test"}
cObj := CriticalObject(project1)
threadD := AhkThread("
(
project1 := CriticalObject(" (&cObj) ")
MsgBox `% project1.Key
)")
While threadD.ahkReady()
	Sleep 200
But fail when using a separate script file
Main file:

Code: Select all

project1:={Key:"this is a test"}
cObj := CriticalObject(project1)
threadD := AhkThread("threadfile.ahk",,1)
While threadD.ahkReady()
	Sleep 200
Thread File:

Code: Select all

project1 := CriticalObject(" (&cObj) ")
MsgBox % project1.Key
Also, I have noticed that in the docs AhkThread()
https://hotkeyit.github.io/v2/docs/commands/AhkThread.htm
It shows the syntax to be:
OutputVar := AhkThread(ScriptOrFile, Parameters, Title, ScriptIsFile, DllToUse)
where 'ScriptIsFile' is the 4th Parameter but will only work if it is used as the 3rd parameter.
guest3456
Posts: 3106
Joined: 09 Oct 2013, 10:31

Re: AhkThread() from inline code vs separate file

17 Feb 2020, 21:40

RazorHalo wrote:
17 Feb 2020, 21:35
But fail when using a separate script file
Main file:

Code: Select all

project1:={Key:"this is a test"}
cObj := CriticalObject(project1)
threadD := AhkThread("threadfile.ahk",,1)
While threadD.ahkReady()
	Sleep 200
Thread File:

Code: Select all

project1 := CriticalObject(" (&cObj) ")
MsgBox % project1.Key
obvioulsy that's going to fail, the thread file makes no sense.. you're passing a string to the CriticalObject function, you're not passing the address of anything, you don't even have the address of it. this has nothing to do with AhkThread at all, but rather simple strings and variables and expressions. when the code is inline, you have the value of the cObj variable from earlier in the script

if you want to do it that way, you might as well #include the file at that location

User avatar
RazorHalo
Posts: 32
Joined: 21 Dec 2015, 21:23

Re: AhkThread() from inline code vs separate file

17 Feb 2020, 23:31

Ah Ok, I see now. For some reason I was thinking that AhkThread() treated the script file it created the thread from like it was part of the main code, just as if it had been inline code, not a completely separate script.
guest3456
Posts: 3106
Joined: 09 Oct 2013, 10:31

Re: AhkThread() from inline code vs separate file

17 Feb 2020, 23:34

RazorHalo wrote:
17 Feb 2020, 23:31
Ah Ok, I see now. For some reason I was thinking that AhkThread() treated the script file it created the thread from like it was part of the main code, just as if it had been inline code, not a completely separate script.
yeah, that's how #include works, but i doubt thats how AhkThread() works


Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 14 guests