Message path and accessing variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Message path and accessing variables
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.
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.
Re: Message path and accessing variables
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.
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.
Re: Message path and accessing variables
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).
Regards,
Sri
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).
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... well why would you want to do that?
Regards,
Sri
Re: Message path and accessing variables
Yes.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).
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.
Re: Message path and accessing variables
What would be an example of relative referencing of properties?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.
Re: Message path and accessing variables
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"
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"
Re: Message path and accessing variables
Thanks!
Sri.
Sri.