messages path

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

messages path

Post by jmburnod » Sat May 14, 2011 2:59 pm

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
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: messages path

Post by Mark » Sat May 14, 2011 4:20 pm

Jean-Marc,

Why do you expect an error?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: messages path

Post by jmburnod » Sat May 14, 2011 5:04 pm

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
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: messages path

Post by Mark » Sat May 14, 2011 7:38 pm

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

Code: Select all

send "foo" to grp 1
from the message box, I get:

group
card
stack

but I wouldn't expect "card" to show up. If I execute

Code: Select all

send "foo" to this cd
I get

card
group
stack

which is as expected.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: messages path

Post by bn » Sat May 14, 2011 9:18 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: messages path

Post by Mark » Sat May 14, 2011 9:23 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: messages path

Post by bn » Sat May 14, 2011 10:49 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: messages path

Post by Mark » Sat May 14, 2011 11:52 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: messages path

Post by bn » Sun May 15, 2011 12:10 am

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: messages path

Post by Mark » Sun May 15, 2011 9:46 am

Hi Bernd,

Sure, where should I send it?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: messages path

Post by bn » Sun May 15, 2011 11:16 am

Hi Mark,

Code: Select all

 put base64decode("bmlnZ2VtYW5uQHVuaS13aC5kZQ==")
thanks

Kind regards

Bernd

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: messages path

Post by Mark » Sun May 15, 2011 11:26 am

001010100001011010000110011101101101011011001110
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: messages path

Post by bn » Sun May 15, 2011 12:35 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: messages path

Post by Mark » Sun May 15, 2011 2:55 pm

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?

Code: Select all

send "foo" to bg 1
To not break HyperCard stacks, you should only get

background

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: messages path

Post by bn » Sun May 15, 2011 3:42 pm

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

Post Reply