[10.4] Global Variables

Hey folks I’m a Applescripting newb and cannot figure something out. Is there a way to create a variable that is accessible through various sub-routines within the script? Here’s a code snippit:

on incrementProgBar(windowName, displayData, dName)
	set counter to counter + 1
	tell application "ProgBar"
		tell text field "field_one" of window windowName to set contents to displayData
		tell progress indicator "prog_one" of window windowName to set content to counter
		tell text field "field_two" of window windowName to set contents to dName
	end tell
end incrementProgBar

That sub routine gets called multiple times from the main script body and from other sub routines, but it errors out with saying ‘counter’ not defined or some such error.

In the main body of the script the very first thing I do is

global counter 
set counter to 1

so why would the sub routines not have acced to it?

Thanks,

Jay

For me, this works as excepted:

global counter

set counter to 1

on test()
	set counter to counter + 1
end test

return test()

Do you even need a global variable? Here is what I use for my progress indicator:

on increase by thisMuch
	tell window 1 of application "Progress" to tell progress indicator 1 to set content to (content + thisMuch)
end increase

If you always want it to increase by one, you could do this:

on increase
	tell window 1 of application "Progress" to tell progress indicator 1 to set content to (content + 1)
end increase