Local/Global variable warning...

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
iguru42
Posts: 9
Joined: 25 Mar 2015, 13:35

Local/Global variable warning...

20 Apr 2018, 14:08

Sorry I know this is super basic but I'm not getting it. I just need my count variable to work.

Code: Select all

; Auto Unarchive on ArchiveOne
; Ver 0.1
; By iguru42
;
;Ver 0.1 notes
; Initial attempt to modify journal archive script to do unarchive instead.
; It must be run with admin priviliges, right click and run as admin.
; Just TAB will move between some frames of ArchiveOne Admin
;

;Notes: command hotkeys I always forget !=alt, ^=ctrl, +=shift, #=windows, *=wildcard

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode 2
#SingleInstance Force
#Persistent
DetectHiddenWindows, On 
DetectHiddenText, On 
SetTitleMatchMode Slow
CoordMode,mouse,window 
count=1

Loop
{
filedelete, status.txt
Sleep 3000
SS("Script Started")
RA()
SS("Unarchive Process running, waiting for completion")
WFC()
SS("Unarchive complete, iterating by 1 and starting from beginning")
count++
}

;FUNCTIONS

RA()	{ ;Run Unarchive
	send unarchive test
	send !ae
	sleep 1000
	send !wb
	sleep 1000
	click 293,138
	send !r
	sleep 1000
	send {tab 3}
	sleep 1000
	send {down %count%}
;the 3 lines below this are commented out for testing purposes.
	;send !a
	;send {enter 3}
	;send !ar{enter}
	}

SS(TTS)	{ ;Send text to file name status in the current folder
	FormatTime, timestamp,, HH:mm:ss 
	fileappend, %timestamp% : %tts%`r`n, status.txt
	}

SHours(sleephours)	{ ;Sleep for X number of hours.
	loop, % sleephours
		{
		FormatTime, timestamp,, HH:mm:ss 
		fileappend, %timestamp% : Pausing for 1 hour`r`n, status.txt
		loop, 60
			{
			mousemove, 1, 0, 0, R
			sleep 30000
			mousemove, -1, 0, 0, R
			sleep 30000
			}
		}
	}
	
WFC()	{ ; Wait for completed, check the Policy Status window for both Phase buttons to be greyed out, when found exit loop.  
	loop
		{
		mousemove, 1, 0, 0, R
		sleep 5000
		mousemove, -1, 0, 0, R
		sleep 5000
		ImageSearch, FoundX, FoundY, 0,0,1999,1999, *50 sconsole.png
		sleep 10000
		if ErrorLevel = 0
		break
		}
	sleep 1000
	send +{tab 3}{enter}
	sleep 5000
	}

donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: Local/Global variable warning...

20 Apr 2018, 14:28

Code: Select all

global count
count = 1
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Local/Global variable warning...

20 Apr 2018, 14:29

either declare you variable super-global outside the scope of any function

Code: Select all

global count := 0
func() {
count++
}
state youre referencing a global variable inside your function

Code: Select all

count := 0
func() {
global count
count++
}
or pass it as an argument

Code: Select all

count := 0
count := func(count)
func(var) {
var++
return var
}
but before u do all of this, read some of the docs

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee and 376 guests