Global Procedure
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Global Procedure
How can I create a global procedure that I can call later from other cards?
And global variables?
Thanks,
Carel
And global variables?
Thanks,
Carel
Re: Global Procedure
Hi.
You must read the user guide and play with the lessons and tutorials. And the dictionary. Not cover to cover, but if you had looked up "global", you would have had considerable information about your second question. Global variables are explicitly declared in a script or handler, and are thereafter available anywhere at any time in the current session.
"Global procedures" are, I think you must mean, handlers that reside in scripts that are high in the message hierarchy, perhaps at the stack or backscript level. They may also reside in other stacks put "into use". These handlers may then be called from object handlers, and can be thought of as "libraries".
But this information is useless unless you have a sense of the message path. This is a fundamental idea in LC. Write back with any questions or problems you may ever have, but you must get going by yourself until you learn how to drive. We will give you directions anywhere at all once that happens.
Craig Newman
You must read the user guide and play with the lessons and tutorials. And the dictionary. Not cover to cover, but if you had looked up "global", you would have had considerable information about your second question. Global variables are explicitly declared in a script or handler, and are thereafter available anywhere at any time in the current session.
"Global procedures" are, I think you must mean, handlers that reside in scripts that are high in the message hierarchy, perhaps at the stack or backscript level. They may also reside in other stacks put "into use". These handlers may then be called from object handlers, and can be thought of as "libraries".
But this information is useless unless you have a sense of the message path. This is a fundamental idea in LC. Write back with any questions or problems you may ever have, but you must get going by yourself until you learn how to drive. We will give you directions anywhere at all once that happens.
Craig Newman
Re: Global Procedure
Thanks for the info Craig.
I looked up global variables - easy.
Just a quick question: So for my public "procedure"
I can use:
command MyCommand
do some things
end MyCommand
or function MyFunction
return something
end MyFunction
can I just put this on the stack script and then access it from any card?
Gonna try it now
I looked up global variables - easy.
Just a quick question: So for my public "procedure"
I can use:
command MyCommand
do some things
end MyCommand
or function MyFunction
return something
end MyFunction
can I just put this on the stack script and then access it from any card?
Gonna try it now

Re: Global Procedure
Right on. You will be exhilarated.
Again, get hold of the message hierarchy. This construct is utterly fundamental. It gives enormous power to you, and is very simple to grasp.
Craig
Again, get hold of the message hierarchy. This construct is utterly fundamental. It gives enormous power to you, and is very simple to grasp.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 10062
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Global Procedure
For an overview of the options for extending the message path, this may help:
Extending the LiveCode Message Path
An introduction to using Libraries, FrontScripts, BackScripts and Behaviors
in RunRev's LiveCode Programming Language
http://www.fourthworld.com/embassy/arti ... _path.html
Extending the LiveCode Message Path
An introduction to using Libraries, FrontScripts, BackScripts and Behaviors
in RunRev's LiveCode Programming Language
http://www.fourthworld.com/embassy/arti ... _path.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Global Procedure
Thanks for the input guys - I'm finally starting to enjoy livecode now.
I have this conundrum though:
I have this in my stack script:
global question, answer1, answer2, answer3, correctanswer, picturenumber, GlobalQuestionNumber
command Populate
answer "test"
put question[GlobalQuestionNumber] into field questionbox on card 2
put answer1[GlobalQuestionNumber] into field answer1box on card 2
put answer2[GlobalQuestionNumber] into field answer2box on card 2
put answer3[GlobalQuestionNumber] into field answer3box on card 2
end Populate
and this in a button script on card 1:
put 1 into GlobalQuestionNumber
Populate -- answer "test" executes but nothing else
put answer2[GlobalQuestionNumber] into field answer2box on card 2 -- this also executes correctly
That indicates that my command Populate runs, but why does only the answer "test" executes and not the other code?
Thanks again,
Carel
I have this conundrum though:
I have this in my stack script:
global question, answer1, answer2, answer3, correctanswer, picturenumber, GlobalQuestionNumber
command Populate
answer "test"
put question[GlobalQuestionNumber] into field questionbox on card 2
put answer1[GlobalQuestionNumber] into field answer1box on card 2
put answer2[GlobalQuestionNumber] into field answer2box on card 2
put answer3[GlobalQuestionNumber] into field answer3box on card 2
end Populate
and this in a button script on card 1:
put 1 into GlobalQuestionNumber
Populate -- answer "test" executes but nothing else
put answer2[GlobalQuestionNumber] into field answer2box on card 2 -- this also executes correctly
That indicates that my command Populate runs, but why does only the answer "test" executes and not the other code?
Thanks again,
Carel
Re: Global Procedure
Did you declare the global in the button script? Globals have to be declared in each script (or handler) they will be used.
Craig Newman
Craig Newman
Re: Global Procedure
aaahhhhh - thank you! - I read somewhere that if you declare it in the stack script you don't have to declare it again - maybe I just understood wrong.
Re: Global Procedure
Half wrong.
Declarations may be made in the script of any object, outside of any handler. In such a case, all handlers FOLLOWING the declaration will have access. But only in that script, not beyond. The shouting is why most declarations are made at the top of the script. Similarly, script local (not global) variables are declared, er, similarly.
However, if you declare a global in the stack script, and also declare it in the script of a control somewhere, that global is available by virtue of it being so declared.
If the declaration is made in a handler, it must be made in each handler that needs it, global or not. These are truly local.
Craig Newman
Declarations may be made in the script of any object, outside of any handler. In such a case, all handlers FOLLOWING the declaration will have access. But only in that script, not beyond. The shouting is why most declarations are made at the top of the script. Similarly, script local (not global) variables are declared, er, similarly.
However, if you declare a global in the stack script, and also declare it in the script of a control somewhere, that global is available by virtue of it being so declared.
If the declaration is made in a handler, it must be made in each handler that needs it, global or not. These are truly local.
Craig Newman
Last edited by dunbarx on Thu Aug 15, 2013 11:17 pm, edited 1 time in total.
Re: Global Procedure
Thanks again Craig.
This is something I have to get used to - back in the day when I learned Turbo Pascal (from a book!) I used to keep most of my variables global and that habit filtered down to just about every programming language I used. (Yes I know it is bad practise)
I'm glad you guys are online when I'm programming (at night)
- going to bed just now though, keep well.
This is something I have to get used to - back in the day when I learned Turbo Pascal (from a book!) I used to keep most of my variables global and that habit filtered down to just about every programming language I used. (Yes I know it is bad practise)
I'm glad you guys are online when I'm programming (at night)

Re: Global Procedure
No sweat.
Since you are a programmer but new to xTalk, think about abandoning globals altogether in favor of custom properties. Do you know about these?
Craig
Since you are a programmer but new to xTalk, think about abandoning globals altogether in favor of custom properties. Do you know about these?
Craig