Right, so I have a large chunk of code that I need to call repeatedly, but for some reason whenever I put it into a function and then call the function later, something goes wrong. I have tried declaring all variables as global, but it seems that that isn't the issue. It's happened to me multiple times and I'd usually just end up pasting the contents of the function wherever it was called instead of dealing with this mess, but this time I have a sizeable chunk that I will likely need to edit a few times.
I've pasted the code below, if that'd help. It seems to completely skip over the "If ( ImgSearch ...." sections, though all of the variables I have used are declared globally much earlier.
I'd rather not paste this where the current "CoreProcess()" function calls are, as there are around 6 of them, but I'm not sure what other options I have. Any ideas?
CoreProcess() { WinActivate, iv char-1.vi If ( ImgSearch = 1 ) { WinActivate, iv char-1.vi MemCheck := 0 z = 0 MemSearch: While ((MemCheck != 1)) { WinActivate, iv char-1.vi ToolTip, Searching for memory. (%z% runs), 0, 0 Sleep 500 z:=z+1 WinActivate, iv char-1.vi ImageSearch, PosXMem, PosYMem, 1, 1, A_ScreenWidth, A_ScreenHeight,*125 Files \memory.bmp ;ImageSearch, xx, yy, 1, 1, 1919, 1079,*12 selec.png if ErrorLevel = 2 { } else if ErrorLevel = 1 { MemCheck := 0 } else { Tooltip MemCheck := 1 PosXMem := PosXMem + 60 PosYMem := PosYMem + 50 } } } PosX = 63 PosY = 57 WinActivate, iv char-1.vi Click %PosXMem%, %PosYMem% Send {Backspace}{Backspace}%Mem% If ( ImgSearch = 1 ) { WinActivate, iv char-1.vi RunCheck := 0 z = 0 RunSearch: While ((RunCheck != 1)) { ToolTip, Searching for Run. (%z% runs), 0, 0 Sleep 500 z:=z+1 WinActivate, iv char-1.vi ImageSearch, PosX, PosY, 1, 1, A_ScreenWidth, A_ScreenHeight,*125 Files\run2.png ;ImageSearch, xx, yy, 1, 1, 1919, 1079,*12 selec.png if ErrorLevel = 2 { } else if ErrorLevel = 1 { RunCheck := 0 } else { Tooltip RunCheck := 1 PosX := PosX + 10 PosY := PosY + 10 } } } WinActivate, iv char-1.vi Click %PosX%, %PosY% WinActivate, iv char-1.vi Exists = 0 While (Exists != 1) { WinActivate, Select a file to save. IfWinExist, Select a file to save. { Exists := 1 } } CoordMode Mouse, relative WinActivate, Select a file to save. PosXName := 660 PosYName := 400 WinActivate, Select a file to save. Click %PosXName% %PosYName% Send {Backspace}^a{Backspace} Send S3 IV %Temp%K Pins %Pins% PosXSave := 763 PosYSave := 403 WinActivate, Select a file to save. Click %PosXSave% %PosYSave% CoordMode, mouse, screen }