Simple Scoping Question

Graham Samuel livfoss at blueyonder.co.uk
Wed Apr 20 14:33:47 EDT 2005


On Wed, 20 Apr 2005 16:33:47 +0100, David Burgun  
<dburgun at dsl.pipex.com> wrote:
> Hi,
>
> I am confused, in the case where "StackA" calls a Function in
> "GlobalStack", when in that function should "this stack" return
> "StackA" or "GlobalStack" ?
>
> I want it to return "StackA" so that the functions are general.
>

I think it works the way you want: if  you put a function in your  
mainstack "GlobalStack" whose script is

function ReportMyName
   return the short name of this stack
end ReportMyName

and then you call it from your substack "StackA" (the script of  
"GlobalStack" will automatically be in the message path) say in a  
button which is scripted

on mouseUp
   put reportMyName()
end mouseUp

You'll get "StackA" in the message box, but if you run that script from  
"GlobalStack", you'll get "GlobableStack", or from another substack  
"StackB", then that name. So within the function, 'this' still refers  
to the calling stack. I think this is what you expected.

HTH

Graham
------------------------------------------------------------------------ 
---
Graham Samuel / The Living Fossil Co. / UK and France



More information about the use-livecode mailing list