Globals
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Globals
Hi everyone,
Can anybody please tell me what's going wrong in the following snippet? Instead of getting the value returned by getApplicationPath(), I'm getting nothing. I've cut the script to bits to try to see what is happening and it is now driving me up the wall - there's not a lot left to cut anymore. The getApplicationPath() function just returns the path of the application in text and it is working fine.
global x
put getApplicationPath() into x
on mouseUp
put x into field "textArea"
end mouseUp
Thanks a mil,
Mike
Can anybody please tell me what's going wrong in the following snippet? Instead of getting the value returned by getApplicationPath(), I'm getting nothing. I've cut the script to bits to try to see what is happening and it is now driving me up the wall - there's not a lot left to cut anymore. The getApplicationPath() function just returns the path of the application in text and it is working fine.
global x
put getApplicationPath() into x
on mouseUp
put x into field "textArea"
end mouseUp
Thanks a mil,
Mike
Re: Globals
Your "put getApplicationPath() into x" needs to be in a handler; is it? Otherwise it will never happen.
Also, each script (not each handler in a script, but the script of each object) that uses your global needs the declaration "global x" which you can place at the top of the script, outside of any handlers.
Also, each script (not each handler in a script, but the script of each object) that uses your global needs the declaration "global x" which you can place at the top of the script, outside of any handlers.
Best wishes,
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/
Re: Globals
Thanks.
I was of the opinion that I could initialise variables outside handlers and that it wasn't required to reuse the 'global' statement once the original declaration of the global is in the same script.
I've tried both changes and It still doesn't work though.
I was of the opinion that I could initialise variables outside handlers and that it wasn't required to reuse the 'global' statement once the original declaration of the global is in the same script.
I've tried both changes and It still doesn't work though.
Re: Globals
Hi Mike,
it DOES work this way! Could you post your code again please?
You could also initialise the global when the stack opens, so the global is ready to use then! Do like this:
Then you can use the global wherever in your app like in your mouseup handler:
Best
Klaus
it DOES work this way! Could you post your code again please?
You could also initialise the global when the stack opens, so the global is ready to use then! Do like this:
Code: Select all
on openstack
global x
put getApplicationPath() into x
# More openstack stuf...
end openstack
Code: Select all
on mouseUp
global x
put x into field "textArea"
end mouseUp
Klaus
Re: Globals
macroman...
A silly example using your function name
be well
Dixie
A silly example using your function name
Code: Select all
global x
function getApplicationPath harry
put word 1 to 3 of the long name of this stack into harry
return harry
end getApplicationPath
on mouseDown
put getApplicationPath() into x
end mouseDown
on mouseUp
put x
end mouseUp
Dixie
Re: Globals
HARRY???
Luv it!

Luv it!



Re: Globals
Thanks guys, we're off again and it's working. I'll paste the rest of the code back in now and see if it explodes (c;
I think years of C, C++, Delphi, PHP and many others have taken their toll and I need to start thinking in terms of handlers.
Once again, thanks a mil!
Mike
I think years of C, C++, Delphi, PHP and many others have taken their toll and I need to start thinking in terms of handlers.
Once again, thanks a mil!
Mike
Re: Globals
Hi Mike,
you're welcome!
you're welcome!

Re: Globals
Yes, code must be in a handler AND the handler has to be called. (Event-driven.)
Best wishes,
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/