AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Global Betwwen Scripts?
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sat Jul 21, 2007 10:08 pm    Post subject: Global Betwwen Scripts? Reply with quote

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
Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Sun Jul 22, 2007 2:02 am    Post subject: Reply with quote

Either you simply store the elapsed-time in a txt- or ini-file

or you use "RegisterCallback()" and "DLLCall" for that matter
Back to top
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sun Jul 22, 2007 3:28 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
Dewi Morgan



Joined: 03 Oct 2005
Posts: 186

PostPosted: Sun Jul 22, 2007 5:25 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sun Jul 22, 2007 5:33 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Dewi Morgan



Joined: 03 Oct 2005
Posts: 186

PostPosted: Sun Jul 22, 2007 3:05 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Sun Jul 22, 2007 3:50 pm    Post subject: Reply with quote

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.
Back to top
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sun Jul 22, 2007 4:30 pm    Post subject: Reply with quote

"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%

Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Sun Jul 22, 2007 4:35 pm    Post subject: Reply with quote

Are you shure, you want me to help you?
Back to top
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sun Jul 22, 2007 4:50 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 1019
Location: London, UK

PostPosted: Sun Jul 22, 2007 4:56 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sun Jul 22, 2007 5:06 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sun Jul 22, 2007 5:58 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Dewi Morgan



Joined: 03 Oct 2005
Posts: 186

PostPosted: Sun Jul 22, 2007 7:59 pm    Post subject: Reply with quote

Sharing a small file on a virtual, in-memory filesystem does seem easiest and possibly fastest.
_________________
Yet another hotkeyer.
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 169

PostPosted: Sun Jul 22, 2007 8:06 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group