Message path and accessing variables

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Message path and accessing variables

Post by sritcp » Fri Jun 29, 2012 2:03 am

I am trying to understand what else travels along with the message.

Let's say a button is clicked and the mouseUp message is simply passed on from the button to the card to the stack, where the message is implemented.
Let's also say that
i) the object script has declared a script-local variable, sObject and a global variable gObject
ii) the card script has declared a script-local variable, sCard and a global variable gCard
iii) the stack script has declared a script-local variable, sStack and a global variable gStack
Assume these variables are not declared anywhere else (e.g., inside a handler).

Which of these variable does the message (sent to the object and executed at the stack level) have access to?

Thanks,
Sri.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Message path and accessing variables

Post by sturgis » Fri Jun 29, 2012 5:20 am

If the event (mouse click) is handled by the object, it has access to the local script variables of that object as well as any declared local varaibles in the mouseup and mousedown handlers of the object. It also of course has access to the global that is declared in the object script.

If the message is then passed (pass messagename IE pass mouseup) OR the message was not handled by the object (the target that was clicked) it moves up to the card. In the card the same rules apply. It can access script locals, declared globals. But it can't access the script local variables from other levels of the message path. (object, or stack) If you wish to access the global declared in the object (gObject) or the stack (gStack) you must declare them in the script or handler you wish to use them in.

Same for the stack. Globals declared elsewhere can be declared here to access teh global value. Local variables are only local in the scope they're declared (IE Handler declared local is only available to that handler, script local to that script)

the first parameter of a mouseup is the button number.
on mouseUp pBtn
answer pBtn -- display the button number in answer dialog
end mouseUp


Technically if you wish the mouseup handler to run for object then card then stack, and you want to pass a value along you could use dispatch

dispatch "mouseup" to card 1 with pBtn,"myvaluetopass"

and the handler on the card
on mouseUp pBtn, pVar
put pBtn && pVar --viola', myvaluetopass shows up in 2nd parameter
end mouseup

But for this example .. well why would you want to do that? Write a handler or function to do what you need and call that instead.
sritcp wrote:I am trying to understand what else travels along with the message.

Let's say a button is clicked and the mouseUp message is simply passed on from the button to the card to the stack, where the message is implemented.
Let's also say that
i) the object script has declared a script-local variable, sObject and a global variable gObject
ii) the card script has declared a script-local variable, sCard and a global variable gCard
iii) the stack script has declared a script-local variable, sStack and a global variable gStack
Assume these variables are not declared anywhere else (e.g., inside a handler).

Which of these variable does the message (sent to the object and executed at the stack level) have access to?

Thanks,
Sri.

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Message path and accessing variables

Post by sritcp » Sun Jul 01, 2012 11:07 pm

Thanks, sturgis! So, if I understand correctly, the answer to my question is
a message sent to the object and executed at the stack level will have access only to sStack and gStack (both declared at the top of the stack script).
.. well why would you want to do that?
I am writing an app where almost all of my coding is at the stack script level. This is so that when I add an additional card (each card is a language exercise, to give you an idea), I have to write no additional script. Since there are card-specific data (number of clickable images on a card, or their names, etc.), these have to be created on openCard as global variables (rather than card script local), so that the program (which is at the stack script level) can use them.

Regards,
Sri

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Message path and accessing variables

Post by sturgis » Sun Jul 01, 2012 11:16 pm

Thanks, sturgis! So, if I understand correctly, the answer to my question is
a message sent to the object and executed at the stack level will have access only to sStack and gStack (both declared at the top of the stack script).
Yes.

And: gStack (a global) can be seen other places if the global is declared.

And properties can be seen from anywhere as long as you give a full path to them. (the myproperty of button "mybutton" of card "mycard3" of stack "thatstackoverthere") Relative referencing of properties works as well.

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Message path and accessing variables

Post by sritcp » Tue Jul 03, 2012 12:37 am

And properties can be seen from anywhere as long as you give a full path to them. (the myproperty of button "mybutton" of card "mycard3" of stack "thatstackoverthere") Relative referencing of properties works as well.
What would be an example of relative referencing of properties?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Message path and accessing variables

Post by sturgis » Tue Jul 03, 2012 1:07 am

From an object itself:
get the whateverproperty of me

from an object on a stack:
get the whateverproperty of this card -- or card "cardname" which would locate the correct card in the current stack
get the whateverproperty of this stack

From an object on a card getting a property from another object on the same card
get the whateverproperty of field "myfield"

from a stack or card accessing an object property on the same card.
get the whateverpropterty of button "mybutton"

Accessing a property on an object of a different stack requires absolute pathing
(from stack mystack1, getting a property from mystack2, card 4, button "mybutton")
get the whateverproperty of button "mybutton" card 4 of stack "mystack2"

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Message path and accessing variables

Post by sritcp » Tue Jul 03, 2012 6:05 pm

Thanks!

Sri.

Post Reply