Global variable doesn't work

Hi

to start with, yes, i’ve read “Variable Scope in Applescript and Applescript Studio”, but still, my variable aren’t global.

Here’s how I defined them:


on clicked theObject
	(*Add your script here.*)
	if name of theObject is "login_button" then
		start progress indicator "login_indicator" of view "login_view" of window "doupload"
		set visible of view "login_indicator" of view "login_view" of window "doupload" to true
		
		[b]global firma_id, ftp_username, ftp_passwort
		set firma_id to ""
		set ftp_username to ""
		set ftp_passwort to ""[/b]
		
		set passwort to (get string value of text field "passwort_feld" of view "login_view" of window "doupload")
		set firma_id to (get string value of text field "firma_id_feld" of view "login_view" of window "doupload")
		set md5hash to (do shell script "md5 -q -s '" & passwort & "'")
		set ausgabe to (do shell script ("curl http://localhost/test.php?id=" & firma_id & "\\&md5=" & md5hash))
		set ausgabe to splitText(";", ausgabe)
		--hier ausgaben überprüfen
		
		set login_status to item 1 of ausgabe
		[b]set ftp_username to item 2 of ausgabe[/b]
		set ftp_passwort to item 3 of ausgabe

i want to use the three variables in a function “on prozessEinleiten(pathNames)” but i get the error, the variables aren’t defined.

I really don’t know why this happens, since the variables are set global, and according to the thread and the apple dev center this should work.

i already tried putting the “global …” on other parts of the script, but it didn’t work neighter.

Try defining the globals as properties and put them outside of the clicked handler.

Thanks it worked.
But i still wonder WHY it didn’t with the global?
After all, that’s what they are supposed to be :slight_smile:
Is this a common bug or a programming error on my turn?

I think the variable you declare as a global one, is only global when you say you want to use the global. If you go to another handler you have to first say you want to use the global variable, else the app would try to get the local one. Like this:

on clicked theObject
	global theVar
	set theVar to "Variable Content"
end clicked

on DoSomething()
	global theVar
	get theVar
end DoSomething

I think if you declare the variables as global outside a handler, all handlers automatticly use the global one and not the local one. Example:

global theVar

on clicked theObject
	set theVar to "Variable Content"
end clicked

on DoSomething()
	get theVar
end DoSomething

Again, I only think that’s the problem. I really don’t know.

Hope it works,
ief2

ief2, I had a similar problem and this indeed fixed the issue for me. Thanks for your reply!
-Fred