AutoHotkey Community

It is currently May 27th, 2012, 6:01 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: November 19th, 2005, 5:31 pm 
Offline

Joined: November 26th, 2004, 8:31 am
Posts: 21
I tend to be slow with adopting new versions of AutoHotKey, but recently I have decided to upgrade (from 1.0.27 to 1.0.40.08). My fears were confirmed when my scripts stopped working. It seems that I am unable to create global variables now. Can anyone help me?

An excerpt from WGET.AHK (I kept everything that's outside of functions, but removed all functions, because they are unnecessary):

Code:
WGET_ExePath = C:\Utils\wget.exe
WGET_TargetDir = D:\Tmp
WGET_Referer =
WGET_UserAgent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

F12::
msgbox, var = %WGET_ExePath%


For some strange reason, the message box displays "var = ". This same construct worked fine in the older versions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 6:24 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
I tested your code, it works on my machine.
AHK 1.0.40.08
WinXP Pro SP2

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 6:35 pm 
Offline

Joined: November 26th, 2004, 8:31 am
Posts: 21
Interesting. It seems to work if I run it alone (autohotkey.exe wget.ahk). It even runs if I include it in another script, if I only keep a simple Include in that script. But it won't work in my normal setup. I'll try to locate what causes the problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 6:41 pm 
Offline

Joined: November 26th, 2004, 8:31 am
Posts: 21
Very interesting. This script works:

Code:
WGET_ExePath = C:\Utils\wget.exe
WGET_TargetDir = D:\Tmp
WGET_Referer =
WGET_UserAgent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

F12::msgbox, var = %WGET_ExePath%


But this script does not:

Code:
SetTitleMatchMode, 1
WinWait, Jetico Personal Firewall -
Sleep, 500
WinHide

WGET_ExePath = C:\Utils\wget.exe
WGET_TargetDir = D:\Tmp
WGET_Referer =
WGET_UserAgent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

F12::msgbox, var = %WGET_ExePath%


The first part minimizes Jetico Personal Firewall window when the script is first run.

It's even more interesting if I move the Jetico section AFTER the variables are defined - the script works once again.

Code:
WGET_ExePath = C:\Utils\wget.exe
WGET_TargetDir = D:\Tmp
WGET_Referer =
WGET_UserAgent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

SetTitleMatchMode, 1
WinWait, Jetico Personal Firewall -
Sleep, 500
WinHide

F12::msgbox, var = %WGET_ExePath%


Am I missing something or is it a bug in AutoHotKey?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 6:45 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
because your second code wait indefinitely with WinWait if the Window doesn't exist. Try the code with 1 second as timeout on the winwait. Let's see if that's the problem.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 7:03 pm 
Offline

Joined: November 26th, 2004, 8:31 am
Posts: 21
More tests, more confusing results. Far.ahk always contains this:

Code:
FAR_ExePath = Z:\Far\Far.exe
FAR_Params = /aw

FAR_Run()
{
   global FAR_ExePath, FAR_ExePath
   Run, %FAR_ExePath% %FAR_Params% , , , PID
}


My main script pepak.ahk works fine for:
Code:
#Include FAR.ahk

#f::
   FAR_Run()
   return


It also runs for:
Code:
#Include WGet.ahk
#Include FAR.ahk

#f::
   FAR_Run()
   return


It does not run for:
Code:
#Include WGet.ahk
#Include Gui.ahk
#Include FAR.ahk

#f::
   FAR_Run()
   return


So apparently the problem is in GUI.ahk. And I think I know what is the problem: GUI.ahk looks like this:
Code:
List_File = D:\Tmp\download.lst

GUI_Download_Create(urls,referer)
{
  ; function that creates and populates a GUI window. The contents are not important
}

2GuiEscape:
2GuiClose:
   Gui, Destroy
   return
; ...
GUI_Download_Download:
   urls := GUI_Download_GetSelectedLinks("`r`n")
   listfile = %TEMP%\wget.lst
   FileDelete, %listfile%
   FileAppend, %urls%, *%listfile%
   WGET_Download("-i " . listfile,GUI_Download_Referer)
   Goto, GUI_Download_Cancel


I think the problem is that AutoHotKey parses the sequence of includes as if it was parsing just a single file, line after line. I think it parses the "global" part of Far.ahk as if it was a code belonging to GUI_Download_Download label (so it won't get executed until I actually show the GUI and the user clicks the Download button). Which is a rather logical way to behave, but presents a problem that needs to be addressed: How to tell the AutoHotKey parser that "a block ends here, any further commands once again belong to the main block".


Last edited by pepak on November 19th, 2005, 7:08 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 7:05 pm 
Offline

Joined: November 26th, 2004, 8:31 am
Posts: 21
toralf wrote:
because your second code wait indefinitely with WinWait if the Window doesn't exist. Try the code with 1 second as timeout on the winwait. Let's see if that's the problem.

That is an error indeed, but as the window always exists, it's not a problem in this case.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 7:07 pm 
Offline

Joined: November 26th, 2004, 8:31 am
Posts: 21
For now I have fixed the problem by changing the order of the includes so that GUI.ahk is the last one, but I think this is an issue that needs to be addressed in a more systematic way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2005, 10:59 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Yes, but this addressing has to be done by yourself. this is not an AHK issue.
1) you should write your scripts very clean. E.g. end the autoexec section of each script with a return, exit each script nicely, etc.

2) you can use this setting to run all auto-exec section of the included files.
Code:
;[...]
GoSub, AutoExecScript1
GoSub, AutoExecScript3
GoSub, AutoExecScript3
return ; end autoexec of main script

AutoExecScript1:
#Include Script1.ahk

AutoExecScript2:
#Include Script2.ahk

AutoExecScript3:
#Include Script3.ahk

;[...]
;end of main script

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2005, 6:22 am 
Offline

Joined: November 26th, 2004, 8:31 am
Posts: 21
toralf wrote:
Yes, but this addressing has to be done by yourself. this is not an AHK issue.

Isn't it? I think it is, because AutoHotKey doesn't give me any keyword that would mark an end of a block. Or at least I don't know that keyword. So the only way I can solve this issue is through rearranging the code to make sure no included file will end with something which could be interpreted as an open block. Which might be rather problematic and leads to far less-readable scripts. I should think that a simple (optional) EndBlock would be more useful.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 20th, 2005, 10:16 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Think of #Include as though it does a copy and paste of the included file.

In other words, #Include is designed to be only a simple mechanism for bringing in external files. It isn't designed to merge the auto-execute sections of two or more scripts into one big auto-execute section.

A future version may have a #Merge directive or similar means of merging scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2005, 4:09 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
pepak wrote:
... AutoHotKey doesn't give me any keyword that would mark an end of a block. Or at least I don't know that keyword.
The keyword exists, it is "return".

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, batto, Bing [Bot], dra, HotkeyStick, migz99, mKnight, sjc1000, Wicked, XstatyK and 60 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