Threads exchanging variables

Ask for help, how to use AHK_H, etc.
Galaxis
Posts: 15
Joined: 04 Feb 2016, 20:09

Threads exchanging variables

02 May 2018, 13:09

What is a very basic way to have the 3rd thread identify that the Sky is blue, and time is 10am. Perhaps I wrote the code wrong because I'm getting empty message boxes . :problem:
I don't want to have to use ini files. :facepalm:

Copied a line in the example documentation, but no dice.
Are aliases more appropriate for what I am trying, instead of the code below? https://hotkeyit.github.io/v2/docs/commands/Alias.htm

Code: [Select all] [Download] GeSHi © Codebox Plus

Thread1:=AhkThread("Sky := Blue")
Thread2:=AhkThread("Time := 10am")

Thread3:=AhkThread("
(

Msgbox % Thread1.ahkgetvar.Sky
Msgbox % Thread2.ahkgetvar.Time

)"
)
swagfag
Posts: 718
Joined: 11 Jan 2017, 17:59

Re: Threads exchanging variables

02 May 2018, 16:42

i cant help u further than that, but here are my findings:

1. Thread 1 and 2 the way theyre written in you original script exit immediately after the assignment, so Thread 3 wouldnt have had the chance to read the values even if it could do so correctly in the first place
2. Blue and 10am need to be escaped, else all youre doing is assigning the value of the variables Blue and 10am to Sky and Time, respectively
3. i couldnt for the life of me get ahkassign or alias to work. The only way was to retrieve the variable contents with ahkgetvar and pass them as command arguments to the newly created Thread3, which is just a janky workaround

Code: [Select all] [Download] GeSHi © Codebox Plus

Thread1:=AhkThread("#Persistent`nSky := ""Blue""")
Thread2:=AhkThread("#Persistent`nTime := ""10am""")

Thread3:=AhkThread("
(
#Persistent
Msgbox % A_Args[1]
Msgbox % A_Args[2]
)"
, Thread1.ahkgetvar.Sky . " " . Thread2.ahkgetvar.Time)

Esc::ExitApp


here are my experiments:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



maybe one of the 5 ppl on earth who understand ahk_h can shed some light
Galaxis
Posts: 15
Joined: 04 Feb 2016, 20:09

Re: Threads exchanging variables

02 May 2018, 17:23

Thanks for your efforts <3
I took the chicken way out, and just have all of the threads access and write values to a single .Ini file. Although I wanted to be fancy and have threads talk directly- the ini method is a surefire way to get threads to exchange their variable values. I'm writing Street Fighter V and Final Fantasy XV programs- and converting what was originally in AHK v2. I jumped into AHK version H, simply because the multithreading can combine all my many scripts into one. Street Fighter has over 40 characters, so I didn't want 40 different scripts, LOL :crazy:

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 1 guest