AutoHotkey Community

It is currently May 25th, 2012, 12:10 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Global Betwwen Scripts?
PostPosted: July 21st, 2007, 11:08 pm 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
Is there a way to define variable that is global between different, open, running scripts?

Or maybe a different approach.

I am performing a lot of URLDownloadtofile commands (using it for rest/post kinds of calls). all of the URL request go to the same server, and there is a speed limit of the number of requests per second.

Right now I quite nicely calculate the elapsed miliseconds since the last rest and delay if it is too fast. This script is polling continuously.

The problem is I have 3 other scripts running (for distinctly different purposes. And sometimes they have to go through periods of multiple server requests. (urldownload..). In any one script, I can keep the requests above the min elapsed time restriction.

The problem is when the other scripts are running, the request happen much more frequently, so really the only solution is to somehow share the "tick" number since the last time any script made a server call. (padding with extra sleep ticks will never do it! - just think about it).

So either a shared variable ... or (and I never tried this) but to use one AHK script as sort of a resident library - and the urldownload funciton is in one single script and all the others call it... and this script can keep track of the elapsed time.

I hope this made sense. While my application may be a little unique, certainly the need for shared information (variable or function) is rather common.

Can anyone point me in the right direction?

Thanks!

I have 4 distinctly


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 3:02 am 
Either you simply store the elapsed-time in a txt- or ini-file

or you use "RegisterCallback()" and "DLLCall" for that matter


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 4:28 am 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
Z Gecko wrote:
Either you simply store the elapsed-time in a txt- or ini-file

or you use "RegisterCallback()" and "DLLCall" for that matter


1. Storing the elapsed time to a file would really mess up the timing (i am measuring in milliseconds (or at least 10ths and hundredths).

2. "RegisterCallback()" and "DLLCall" ... I am sure this is useful advice, but unfortunately as vague as saying "why don't you use software". ; )

Has anyone had to solve this same issue? Or made use of RegisterCallback()" and "DLLCall to pass a var between running scripts?

Thanks for the help!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 6:25 am 
Offline

Joined: October 3rd, 2005, 2:42 am
Posts: 186
InterApplication Communication (IAC) is a big and complex field, and I don't think there's an easy way in AHK yet.

Consider a network connection between the two processes?

http://www.autohotkey.com/forum/viewtopic.php?t=13829

_________________
Yet another hotkeyer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 6:33 am 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
Thanks ... ! but that is definitely overkill. I mean the 3-4 scripts are all running on the same computer using the same copy of AutoHotKey.

I hate to say it, but writing a few bytes to a file is looking like the solution. And I mean it ... I hate to say it ; )

Using the clipboard would be kind of neat except that so many other apps (including the user) uses it. Perhaps there is the equivalent of a hidden clipboard?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 4:05 pm 
Offline

Joined: October 3rd, 2005, 2:42 am
Posts: 186
Is using client/server architecture really overkill? A network connection to/from localhost is always rather fast.

Alternatively, use something like vfd to create a virtual drive in memory to store your files - hence, no thrashing.

Alternatively, put them all in the same script, with #include, and use a global. Not always possible because of the limited pseudothreading though.

_________________
Yet another hotkeyer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 4:50 pm 
the advice regarding RegisterCallback was short because there is a working example in the help-file.

And because you are not giving any code, it is quite impossible to give you a specific solution.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 5:30 pm 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
"And because you are not giving any code ..."

oh please. you actually took the time to write that? come on. Thios prpblem is like if AHK did not do trig functions and I asked how to get a cosine value. It's not the syntax, but the actual functionality that's the problem.

But if you want "code" .. here:

Code:
Script 1 ...
UberVariable:=45111

Script 2 ...
msgbox I am script 2 and the UberVariable passed to me by Script 1 is %UberVariable%

Script 1 ...
; changes the value
UberVariable:=97123

Script 2 ...
msgbox Any time I display UberVariable it will reflect any change Script 1 made to it, like now %UberVariable%



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 5:35 pm 
Are you shure, you want me to help you?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 5:50 pm 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
Hey - while I am not a power user, I'm not a novice to AHK and these boards either.

And in this case, implying that one cannot help reply with a solution unless code is posted, points to a misunderstanding of the problem. And the 'prose' code I just posted does more to illustrated the issue than anything else I could have posted.

Again, it's like me asking where the cosine function is ... aside from posting x:=cos(y) there's no other code that will further illustrate the problem.

In the original posting - a value stored in a variable in memory by one running script, say ScriptA_starttime:=A_Tickcount and somewhere else Script B wants to know what the value of ScriptA_starttime is at any given time. Technically, writing the value to a file would achieve this except that when you are talking about a sensitivity of milliseconds it turns out that it needs to be done in memory somehow.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 5:56 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
does this help

helpfile wrote:
Code:
; Example: Have a script receive a custom message and up to two numbers from some other script or program
; (to send strings rather than numbers, see the example after this one).

OnMessage(0x5555, "MsgMonitor")
OnMessage(0x5556, "MsgMonitor")

MsgMonitor(wParam, lParam, msg)
{
    ; Since returning quickly is often important, it is better to use a ToolTip than
    ; something like MsgBox that would prevent the function from finishing:
    ToolTip Message %msg% arrived:`nWPARAM: %wParam%`nLPARAM: %lParam%
}

; The following could be used inside some other script to run the function inside the above script:
SetTitleMatchMode 2
DetectHiddenWindows On
if WinExist("Name of Receiving Script.ahk ahk_class AutoHotkey")
    PostMessage, 0x5555, 11, 22  ; The message is sent  to the "last found window" due to WinExist() above.
DetectHiddenWindows Off  ; Must not be turned off until after PostMessage.

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 6:06 pm 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
Thanks! I am going to try this and report back (I've always wanted to play with the onmessage functions, and now i have a reason). Just scratching my head at how my initial forum search could ever have turned up this solution ; )

Just for the sake of discussion: How would one approach creating a shared library of custom AHK functions (ie 5 running scripts all referencing the one other script that contains a library of custom functions) ... with the caveat that some of the functions needed to operate on variables used by others (UberGlobals, shared clobals, ... whatever). I realize this is probably a challenge in just about every programming language but useful to discuss nonetheless.

Thanks



Superfraggle wrote:
does this help

helpfile wrote:
Code:
; Example: Have a script receive a custom message and up to two numbers from some other script or program
; (to send strings rather than numbers, see the example after this one).

OnMessage(0x5555, "MsgMonitor")
OnMessage(0x5556, "MsgMonitor")

MsgMonitor(wParam, lParam, msg)
{
    ; Since returning quickly is often important, it is better to use a ToolTip than
    ; something like MsgBox that would prevent the function from finishing:
    ToolTip Message %msg% arrived:`nWPARAM: %wParam%`nLPARAM: %lParam%
}

; The following could be used inside some other script to run the function inside the above script:
SetTitleMatchMode 2
DetectHiddenWindows On
if WinExist("Name of Receiving Script.ahk ahk_class AutoHotkey")
    PostMessage, 0x5555, 11, 22  ; The message is sent  to the "last found window" due to WinExist() above.
DetectHiddenWindows Off  ; Must not be turned off until after PostMessage.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 6:58 pm 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
OK - it looks like I have my work cut out for me in comparing some of the approaches. Performance (time sensitivity) is as much of an issue as is relibility - for instance the onmessage approach depends on a visible window, and a small chain of events etc. Registry approaches I fear might be slow too.

I was reading up on DLL calls etc, and of course this is half of my ideal-solution description, but I could not find out if the DLLs allow for 'persistent global variables' (is there a better term?), and also, if there is an easy way to convert an AHK script-library into a DLL.

My application needs to be able to say something like "Don't execute URLDownloadtoFile(myserver..) in ANY running script more than 2 times per second." So the function needs to look to the last tick that ANY script queried myserver and ensure that at least 500ms has passed. At the same time I don't want to pad each script with unneccessary delays - which would not solve the problem. There must be an awareness between processes.

Sharing the value via a small file is looking like the most straight forward solution right now.


Superfraggle wrote:
does this help

helpfile wrote:
Code:
; Example: Have a script receive a custom message and up to two numbers from some other script or program
; (to send strings rather than numbers, see the example after this one).

OnMessage(0x5555, "MsgMonitor")
OnMessage(0x5556, "MsgMonitor")

MsgMonitor(wParam, lParam, msg)
{
    ; Since returning quickly is often important, it is better to use a ToolTip than
    ; something like MsgBox that would prevent the function from finishing:
    ToolTip Message %msg% arrived:`nWPARAM: %wParam%`nLPARAM: %lParam%
}

; The following could be used inside some other script to run the function inside the above script:
SetTitleMatchMode 2
DetectHiddenWindows On
if WinExist("Name of Receiving Script.ahk ahk_class AutoHotkey")
    PostMessage, 0x5555, 11, 22  ; The message is sent  to the "last found window" due to WinExist() above.
DetectHiddenWindows Off  ; Must not be turned off until after PostMessage.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 8:59 pm 
Offline

Joined: October 3rd, 2005, 2:42 am
Posts: 186
Sharing a small file on a virtual, in-memory filesystem does seem easiest and possibly fastest.

_________________
Yet another hotkeyer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 9:06 pm 
Offline

Joined: March 18th, 2005, 8:52 am
Posts: 174
Dewi Morgan wrote:
Sharing a small file on a virtual, in-memory filesystem does seem easiest and possibly fastest.


Unfortunately I was referring to passing the variable between apps via a real disk file - not virtual. Does AHK provide a way to do this virutally? Perhaps by some special file handle?

The above was sort of the same approach as intimated earlier - in having a second or third 'protected clipboard'. But this is beyond me right now.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: cmikaiti, Exabot [Bot], hcx37b, KenC, Maestr0, TedStriker, tomL, Yahoo [Bot] and 44 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group