Page 1 of 1
Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 4:57 pm
by kaveh1000
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?
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 5:08 pm
by mwieder
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.
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 5:59 pm
by FourthWorld
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.
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 6:09 pm
by kaveh1000
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
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 6:22 pm
by dunbarx
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
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 8:06 pm
by FourthWorld
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?
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 8:21 pm
by kaveh1000
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!
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 8:45 pm
by FourthWorld
It sounds like what you want isn't a behavior, but a library.
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 8:47 pm
by kaveh1000
Thanks. Let me mull over it. Didn't think about it in that way
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 9:26 pm
by FourthWorld
Re: Message hierarchy when external stack are used
Posted: Wed Jan 15, 2020 10:07 pm
by kaveh1000
What do you know, Richard. Works fine with just library, no behaviour!! Thank you (and Jacqueline).