Using external script only stack as behaviour
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Using external script only stack as behaviour
I have a stack with most of the script in the stack. I want to use an external script only stack and use it as behaviour. So I have done the following:
– I have put the stack script into the script of the stack of a new, script only stack
- I have saved the new stack in the same directory as the main stack, with standard extension .codescript
- I have deleted the script from the main stack
- I have set the behaviour of main stack to the new script only stack, using the Stack inspector and selecting the script only stack from the hierarchical menus
When I open the main stack, I expect it to load the script from the script only stack. So for example it should read the OpenStack handler from the external stack. But it does not. Even when both stacks are open, when I put OpenStack in msg box with the main stack in front, it cannot find handler. But when I have the script only stack in front, it runs OpenStack ok.
What am I missing? Already holding my head in shame as probably obvious
– I have put the stack script into the script of the stack of a new, script only stack
- I have saved the new stack in the same directory as the main stack, with standard extension .codescript
- I have deleted the script from the main stack
- I have set the behaviour of main stack to the new script only stack, using the Stack inspector and selecting the script only stack from the hierarchical menus
When I open the main stack, I expect it to load the script from the script only stack. So for example it should read the OpenStack handler from the external stack. But it does not. Even when both stacks are open, when I put OpenStack in msg box with the main stack in front, it cannot find handler. But when I have the script only stack in front, it runs OpenStack ok.
What am I missing? Already holding my head in shame as probably obvious
Kaveh
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Using external script only stack as behaviour
Attaching minimal example stacks. I have set Main stack to have behaviour of script_stack.livecodescript. In the stack script of the latter I have:
When opening Main Stack why does it not answer "hi"?
Edited:
If the script stack is already open, then I open Main stack then it works. But if not seems Main stack cannot find the script stack on disk. They are both in the same directory.
Code: Select all
on openstack
answer "hi"
end openstack
Edited:
If the script stack is already open, then I open Main stack then it works. But if not seems Main stack cannot find the script stack on disk. They are both in the same directory.
- Attachments
-
- Minimal example.zip
- (1.24 KiB) Downloaded 226 times
Kaveh
Re: Using external script only stack as behaviour
Well, the first (and probably biggest) thing I see is no code in the main stack saying there is a script only stack, calling a script only stack, or really doing anything to let it know where the stack is.
I got an answer dialog with "hi" in it, which I assume is what your testing for.
Mind you though, I have absolutely no dealings with script only stacks. I am making assumptions about how to call or activate one. Someone that uses them more may chime in with a better answer
Once I added this -
Code: Select all
on preOpenStack
start using stack "path/to/your/script/only/stack/script_stack.livecodescript"
end preOpenStack
Mind you though, I have absolutely no dealings with script only stacks. I am making assumptions about how to call or activate one. Someone that uses them more may chime in with a better answer
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Using external script only stack as behaviour
Thanks a lot Bogs. I thought setting behaviour through the interface and having the script stack in the same directory would be sufficient. But I have now added the script you suggested with slight modification and it works.
Thanks again as ever...
Kaveh
Code: Select all
on preOpenStack
set itemDel to "/"
set the defaultfolder to item 1 to -2 of (the effective fileName of this stack)
put the defaultFolder & "/script_stack.livecodescript" into tScriptStack
start using stack tScriptStack
end preOpenStack
Kaveh
Kaveh
Re: Using external script only stack as behaviour
As I say, I don't use script only stacks (or behaviors, for that matter), and so am hardly the best qualified to answer about their intricacies. Lots of others like and use both, so I *really* hope someone else chimes in with a better or even correct way to use them
It is possible that you were only lacking a path to the stack, so the behavior could make use of it, but I really don't have any clue there.
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Using external script only stack as behaviour
I think the dictionary is misleading in this. It simply states that the pathname to the behavior stack must be of a certain form, to allow portability. This would lead one to think that if both stacks were open, LC would know to look for and use the behavior stack.
After all (again, assuming both stack are open), the "main" stack knows all about the behavior stack, where it is, how big it is, etc. Why should one have to place that stack explicitly in the hierarchy with something like "start using..."?
It gets worse. Even if the behavior stack is a subStack of the main stack, the behavior script still will not be seen right out of the box. Now it seems to me that the main stack is being obstinate. Doesn't it know where its children are?
So at the very least, the dictionary ought to warn of lark's vomit.
Craig
After all (again, assuming both stack are open), the "main" stack knows all about the behavior stack, where it is, how big it is, etc. Why should one have to place that stack explicitly in the hierarchy with something like "start using..."?
It gets worse. Even if the behavior stack is a subStack of the main stack, the behavior script still will not be seen right out of the box. Now it seems to me that the main stack is being obstinate. Doesn't it know where its children are?
So at the very least, the dictionary ought to warn of lark's vomit.
Craig
Re: Using external script only stack as behaviour
Since we have very nice SPECIALFOLDERPATH() codes, there is really no need to mess around with the defaultfolder!kaveh1000 wrote: ↑Tue Oct 15, 2019 2:26 pmCode: Select all
on preOpenStack set itemDel to "/" set the defaultfolder to item 1 to -2 of (the effective fileName of this stack) put the defaultFolder & "/script_stack.livecodescript" into tScriptStack start using stack tScriptStack end preOpenStack
This will also work in the IDE if both stacks are in the same folder:
Code: Select all
on preOpenStack
start using stack (specialfolderpath("resources") & "/script_stack.livecodescript")
end preOpenStack
But the dictionary is no help here and needs to be updated for scriptonly stacks a behavior.
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Using external script only stack as behaviour
Thanks Klaus. I knew that was not the ideal way and I will use your code.
Kaveh
Re: Using external script only stack as behaviour
This will work in the IDE and also in a standalone if you add the script-stacks via the
"Copy files" button in the "Standalone Application Settings".
And exactly therefore we have these specialfolderpath() codes!
"Copy files" button in the "Standalone Application Settings".
And exactly therefore we have these specialfolderpath() codes!
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Using external script only stack as behaviour
Great. I remember you helped me with "copy files" before.
Kaveh
Re: Using external script only stack as behaviour
Erm, that does seem to work, actually. I made the script stack a substack of the main stack, saved it, re-opened the main stack, and got the "hi" answer dialog.
@ Kaveh - I knew someone (cough Klaus cough) would have a better and even shorter way to start using the substack hee hee.
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Using external script only stack as behaviour
Another way is to use the stackfiles to list the relative path. Then you can start using the stack by its short name. But either way works and the main point is that the behavior stack needs to be in RAM to be found.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Using external script only stack as behaviour
Bogs.
Hmmm.
I have a mainStack "xxx" and its subStack "yyyy". I have a stack script in "yyyy", and set the behavior of "xxx" to the long id of stack "yyyy".
I have to start using "yyyy" in order for something in "xxx" to work. If I stop using "yyyy", that functionality goes away. Back and forth...
The original point was that not only are both stacks in memory, but the subStack could not be more intimately tied to the mainStack.
Craig
Hmmm.
I have a mainStack "xxx" and its subStack "yyyy". I have a stack script in "yyyy", and set the behavior of "xxx" to the long id of stack "yyyy".
I have to start using "yyyy" in order for something in "xxx" to work. If I stop using "yyyy", that functionality goes away. Back and forth...
The original point was that not only are both stacks in memory, but the subStack could not be more intimately tied to the mainStack.
Craig
Re: Using external script only stack as behaviour
Hey Craig,
I did say -
However, what I did before posting the last was -
take kaveh's un-altered example up there
make it a substack of the main stack in his example (was intirgued by your post)
save it all that way
PROFIT! Erm, I mean, then I reopened it and it seemed to work.
There was, as I mentioned a few posts up, no code to trigger using it in the original example, and I left it that way, so if it works here on 'nix, but not there on (your os here), I dunno what to tell you. I don't think I'd trust it that way, but it *did* work here, is all.
I did say -
- earlier
However, what I did before posting the last was -
take kaveh's un-altered example up there
make it a substack of the main stack in his example (was intirgued by your post)
save it all that way
PROFIT! Erm, I mean, then I reopened it and it seemed to work.
There was, as I mentioned a few posts up, no code to trigger using it in the original example, and I left it that way, so if it works here on 'nix, but not there on (your os here), I dunno what to tell you. I don't think I'd trust it that way, but it *did* work here, is all.
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Using external script only stack as behaviour
Just as an additional remark.
If I remember right there was last year a post by Mark Waddingham who said it was never intended to use "set the behaviour" to anything else than to a button. And that this may be restricted to buttons in future versions.
If I remember right there was last year a post by Mark Waddingham who said it was never intended to use "set the behaviour" to anything else than to a button. And that this may be restricted to buttons in future versions.
shiftLock happens