[SOLVED] Global AHK Script

Status
Not open for further replies.

gooch

Member
Supporter
RL Member
I was wondering if there was a way to execute an AHK script for all modules, both on launch and exit game. I'm hoping to use %systemName% and %romName% in it.
 

gooch

Member
Supporter
RL Member
I had tried that before you responded, but couldn't get it to work so I thought maybe it was for something else. I still am having trouble getting things to run though.

For example, this does not work for me:

Code:
; Use this function to define any code you want to run in every module on start
StartGlobalUserFeatures(){
	Log("StartGlobalUserFeatures - Starting")
		fileDelete, "C:\Arcade\Utilities\IrfranView\Marquees\%systemName%\marquee.png"
		fileCopy, C:\Arcade\HyperSpin\Media\%systemName%\Images\Wheel\%romName%.png, C:\Arcade\Utilities\IrfranView\Marquees\%systemName%\marquee.png 
		Run C:\Arcade\Utilities\IrfranView\Executables\%systemName%.exe /monitor=2
	Log("StartGlobalUserFeatures - Ending")
}
; Use this function to define any code you may need to stop or clean up in every module on exit
StopGlobalUserFeatures(){
	Log("StopGlobalUserFeatures - Starting")
	; INSERT CODE HERE
	Log("StopGlobalUserFeatures - Ending")
}

But if I comment out the functions it does work.

Code:
; Use this function to define any code you want to run in every module on start
; StartGlobalUserFeatures(){
; 	Log("StartGlobalUserFeatures - Starting")
		fileDelete, "C:\Arcade\Utilities\IrfranView\Marquees\%systemName%\marquee.png"
		fileCopy, C:\Arcade\HyperSpin\Media\%systemName%\Images\Wheel\%romName%.png, C:\Arcade\Utilities\IrfranView\Marquees\%systemName%\marquee.png 
		Run C:\Arcade\Utilities\IrfranView\Executables\%systemName%.exe /monitor=2
; 	Log("StartGlobalUserFeatures - Ending")
; }
; Use this function to define any code you may need to stop or clean up in every module on exit
; StopGlobalUserFeatures(){
; 	Log("StopGlobalUserFeatures - Starting")
	; INSERT CODE HERE
; 	Log("StopGlobalUserFeatures - Ending")
; }

But I'm obviously doing something wrong, and I want to take advantage of the module exit script portion so I can kill %systemName%.exe. Any ideas?
 

djvj

Administrator
Staff member
Developer
You need to learn a bit about ahk scripting first. You are missing a basic rule when using functions. To use an outside variable from the function, you need to make it global first.

Add this line under the start log:
Global systemName,romName
 

gooch

Member
Supporter
RL Member
I guess my problem is not just that the variable isn't working, it's more that the commands aren't executing at all. I should have mentioned that I also tried setting the path manually as a test and it did not execute, it only executed when I commented out the lines I mention above.

When I get a moment, I'll make the outside variable global. Thanks.
 

djvj

Administrator
Staff member
Developer
Yea of course those commands won't work if they are not pointing to a valid file or folder. Taking any component out of those commands means they are no longer valid. Those variables being empty because they are not global means the commands won't work.
 

gooch

Member
Supporter
RL Member
What I mean is, I tried removing the variables like so:

FileDelete, c:\path\to\file.png

And it still did not work.
 

djvj

Administrator
Staff member
Developer
Try not putting quotes around the paths. That is not needed as you are not running them in a cmd window. You need them on the Run command, not the FileDelete one.
 

gooch

Member
Supporter
RL Member
Got it all working, thanks for the advice. Not sure why I couldn't get it working at first without variables, but it's working now - variables and all.

Code:
StartGlobalUserFeatures(){
	Log("StartGlobalUserFeatures - Starting")
		Global systemName,romName
		If ( systemName != "MAME" ) {
			fileDelete, C:\Arcade\Utilities\IrfranView\Marquees\%systemName%\image03.png
			IfExist, C:\Arcade\HyperSpin\Media\%systemName%\Images\Wheel\%romName%.png
				fileCopy, C:\Arcade\HyperSpin\Media\%systemName%\Images\Wheel\%romName%.png, C:\Arcade\Utilities\IrfranView\Marquees\%systemName%\image03.png
			Else
				fileCopy, C:\Arcade\HyperSpin\Media\Main Menu\Images\Wheel\%systemName%.png, C:\Arcade\Utilities\IrfranView\Marquees\%systemName%\image03.png
			Run, C:\Users\gooch\AppData\Roaming\Realtime Soft\UltraMon\3.2.2\Shortcuts\%systemName%.umshortcut, hide
		}
	Log("StartGlobalUserFeatures - Ending")
	}
StopGlobalUserFeatures(){
	Log("StopGlobalUserFeatures - Starting")
		Run, C:\Arcade\Utilities\IrfranView\i_view32.exe /killmesoftly
	Log("StopGlobalUserFeatures - Ending")
}
 
Status
Not open for further replies.
Top