Page 1 of 2
messages path
Posted: Sat May 14, 2011 2:59 pm
by jmburnod
Hi All,
I'm a little confused with the messages path. The doc and the "messages hierarchy" stack of the scripting conference say about background "put after cd in message path"
In this example FromBG and FromCD work fine. I expected an error with FromBG
I have a bg with this script (tested withh rev 4.0 and liveCode 4.5
Code: Select all
on FromBG
MesToCD
end FromBG
on MesToBG
beep
dansmes "MesToBG" && the ticks
end MesToBG
and the cd have this script
Code: Select all
on FromCD
MesToBG
end FromCD
on MesToCD
dansmes "MesToCD"&&the ticks
end MesToCD
on dansmes t
put t
end dansmes
All the best
Jean-Marc
Re: messages path
Posted: Sat May 14, 2011 4:20 pm
by Mark
Jean-Marc,
Why do you expect an error?
Mark
Re: messages path
Posted: Sat May 14, 2011 5:04 pm
by jmburnod
Hi Mark,
Why do you expect an error?
I send a message "FromBG" from the messagesBox to a background
For me the hierarchic position of this message is after the script of the card
FromBG send (not with the send command") a message and the card catch it
If the hierarchic position of bg script is after the card script then the card can't catch
Jean.Marc
Re: messages path
Posted: Sat May 14, 2011 7:38 pm
by Mark
You're right, Jean-Marc,
I tested this with 4.0. If I set the backgroundBehavior of a group to true, it should catch messages after the card receives them, but if I send a message directly to the group, I wouldn't expect the card to catch the message, because the card comes before the group. Yet, it does.
I did the following:
Code: Select all
-- group script:
on foo
put cr & "group" after msg
pass foo
end foo
-- cd script:
on foo
put cr & "card" after msg
pass foo
end foo
-- stack script:
on foo
put cr & "stack" after msg
end foo
I have set the backgroundBehavior of the group to true.
If I execute
from the message box, I get:
group
card
stack
but I wouldn't expect "card" to show up. If I execute
I get
card
group
stack
which is as expected.
Best regards,
Mark
Re: messages path
Posted: Sat May 14, 2011 9:18 pm
by bn
Hi,
from the release notes 4.6.1:
The message path order for backgrounds has been revised slightly (in a backwards-compatible fashion) to take proper account of passing of messages. For a control within a background, the message path is the following:
target
target's owning groups
target's background
card
card's backgrounds not including the target's background
stack
The path for a message sent to a background is:
target background
card
card's backgrounds not including the target's background
stack
Note: The above order effectively means that a background's script is only behind the card for controls it does not contain which retains compatibility with previous interpretations of backgroundBehavior.
This is introduced in 4.6.1
Everything should be clear now
Wouldn't it be a nice question in a Livecode certification examination?, right next to the question: The seven meanings of stack.
Kind regards
Bernd
Re: messages path
Posted: Sat May 14, 2011 9:23 pm
by Mark
Hi Bernd,
No, this isn't entirely clear yet. What if the stack is a HyperCard stack? In that case, all controls are included in one background. According to the docs you just posted, the messages go to the bg before they go to the card. This breaks HyperCard stacks, if I understand it correctly.
Best,
Mark
Re: messages path
Posted: Sat May 14, 2011 10:49 pm
by bn
Hi Mark,
I see your point, one would have to try it with a Hypercard stack. Unfortunately I can not test this.
but doesn't this preserve Hypercards message path?
The above order effectively means that a background's script is only behind the card for controls it does not contain which retains compatibility with previous interpretations of backgroundBehavior
A Hypercard card control (outside of a background, or in Hypercards case the only background) gets a message. If it is not processed then the card gets the message and then the background. I think it should work with Hypercard stacks.
Kind regards
Bernd
Re: messages path
Posted: Sat May 14, 2011 11:52 pm
by Mark
Hi Bernd,
Converted HyperCard stacks contain only one background per card, which contains all background objects of that card (I checked this by opening an old HyperCard stack in Revolution). If messages from objects in groups are sent to the group before they are sent to the card, this will break HyperCard stacks. From what you posted before, I understand that this is indeed the case. For former HyperCard users, the situation with the bug was probably more useful than the situation with the modified message path.
I just opened an old stack in Revolution 3.5. In Rev 3.5, if I send a message to a card, the card script runs before the background script, as expected. If I send the message to the background, the card script runs after the background script. Apparently it was buggy already and it still is, just in a different way
Best,
Mark
Re: messages path
Posted: Sun May 15, 2011 12:10 am
by bn
Hi Mark,
I don't find the description from the release notes 4.6.1 very clear.
One really would have to test it.
I can only speculate, it still could be working for converted Hypercard stacks depending on how one reads the 2nd quote.
a background's script is only behind the card for controls it does not contain
This makes me dizzy.
Could you send me a converted Hypercard stack and I would test it under 4.6.1 ?
Kind regards
Bernd
Re: messages path
Posted: Sun May 15, 2011 9:46 am
by Mark
Hi Bernd,
Sure, where should I send it?
Mark
Re: messages path
Posted: Sun May 15, 2011 11:16 am
by bn
Hi Mark,
Code: Select all
put base64decode("bmlnZ2VtYW5uQHVuaS13aC5kZQ==")
thanks
Kind regards
Bernd
Re: messages path
Posted: Sun May 15, 2011 11:26 am
by Mark
001010100001011010000110011101101101011011001110
Re: messages path
Posted: Sun May 15, 2011 12:35 pm
by bn
Hi Mark,
001010100001011010000110011101101101011011001110
???
I tested the converted Hypercard stack you sent me.
If I click on the button "click me" which is part of the background the message box returns
background
card
I added a new card button, which is not part of the background and the message box returns
card
background
If I remember correctly this is the behaviour you would expect from a Hypercard stack assuming that a message from a member of the background is handled in the background script. If it is not handled by a background script there might be a problem if you catch it on the card script level.
Or am I misunderstanding this?
Kind regards
Bernd
Re: messages path
Posted: Sun May 15, 2011 2:55 pm
by Mark
Hi Bernd,
If you want to mimic the HyperCard behaviour, the button that's part of the group should return
card
background
and if you send a message from the message box directly to the background, it should say
background
A button outside a group won't happen with converted HyperCard stacks. This would be irrelevant.
What happens if you execute the following line in the message box?
To not break HyperCard stacks, you should only get
background
Mark
Re: messages path
Posted: Sun May 15, 2011 3:42 pm
by bn
Hi Mark,
What happens if you execute the following line in the message box?
send "foo" to bg 1
To not break HyperCard stacks, you should only get
background
If I send "foo" from the msg box I get:
background
card
KInd regards
Bernd