Message hierarchy when external stack are used

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Message hierarchy when external stack are used

Post by kaveh1000 » Wed Jan 15, 2020 4:57 pm

I have several external stacks used by a main stack. (Currently all Script only stacks.)

I have the same handler in the main stack as well as in other stacks. I say "pass [handler]" in all cases at the end.

I assume the main stack with get the message first. What determines the hierarchy in other stacks? Is it the order they are loaded on startup?
Kaveh

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Message hierarchy when external stack are used

Post by mwieder » Wed Jan 15, 2020 5:08 pm

If they're all being loaded at the same level (as in "start using xyzzy") then yes, the last one ordered has precedence, and on down the stack of turtles in order of when they were loaded.
If necessary you can change the order by loading one of the stacks again, so that it stays on top of the pile.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Message hierarchy when external stack are used

Post by FourthWorld » Wed Jan 15, 2020 5:59 pm

How are those stacks loaded?

The storage location of a stack doesn't necessarily affect its place in the message path; how you use it does.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Message hierarchy when external stack are used

Post by kaveh1000 » Wed Jan 15, 2020 6:09 pm

Here is my script in the main stack:

Code: Select all

local sLibraryPath

on preOpenStack
   put specialfolderpath("resources") & "/script/MainFile_behaviour.livecodescript" \
         into tBehaviour
   set the behavior of stack "MainFile" to the long ID of stack tBehaviour
   start using stack tBehaviour
   --
   put specialFolderPath("resources") & "/script/" into sLibraryPath
   use_library "Lib_1" -- script only stacks
   use_library "Lib_2"
   ...
   use_library "Lib_n"
end preOpenStack

on use_library pStack
   put pStack & ".livecodescript" into tStackName
   put sLibraryPath & tStackName into tPath
   open stack tPath
   start using stack tPath
end use_library
So Lib_1 etc are Script only stacks, loaded one after another. Let us say each stack has the following script:

Code: Select all

on rawKeyUp
  answer Lib_1
  pass rawKeyUp
end rawKeyUp
Kaveh

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Message hierarchy when external stack are used

Post by dunbarx » Wed Jan 15, 2020 6:22 pm

I would say the the order in which you start using these other stacks places them in the hierarchy. This regardless of the origin of the commands to do so.

In order to rearrange, you would have to "re-start using" them. If you stop using one in the middle, they all collapse, in order.

I think.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Message hierarchy when external stack are used

Post by FourthWorld » Wed Jan 15, 2020 8:06 pm

Jacque raised a very important question in one of the many sprawling parallel threads posted across the forums on this, and I don't recall seeing the answer: Why is the same script being used as both a behavior and a library?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Message hierarchy when external stack are used

Post by kaveh1000 » Wed Jan 15, 2020 8:21 pm

Oh, I don't remember that question. OK so you are saying in these lines:

Code: Select all

set the behavior of stack "MainFile" to the long ID of stack tBehaviour
   start using stack tBehaviour
I have set behavior and in addition I am adding as a library. Does not seem right. I agree. But I just tried removing the second line and a handler is not available to other lib stacks. So although it is set as behaviour the handlers are not seen until I say "start using". Sorry getting a bit too involved and showing my lack of grasp of this area!
Kaveh

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Message hierarchy when external stack are used

Post by FourthWorld » Wed Jan 15, 2020 8:45 pm

It sounds like what you want isn't a behavior, but a library.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Message hierarchy when external stack are used

Post by kaveh1000 » Wed Jan 15, 2020 8:47 pm

Thanks. Let me mull over it. Didn't think about it in that way ;-)
Kaveh

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Message hierarchy when external stack are used

Post by FourthWorld » Wed Jan 15, 2020 9:26 pm

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Message hierarchy when external stack are used

Post by kaveh1000 » Wed Jan 15, 2020 10:07 pm

What do you know, Richard. Works fine with just library, no behaviour!! Thank you (and Jacqueline).
Kaveh

Post Reply

Return to “Talking LiveCode”