Using external script only stack as behaviour

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

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

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

Using external script only stack as behaviour

Post by kaveh1000 » Mon Oct 14, 2019 5:21 pm

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 ;-)
Kaveh

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

Re: Using external script only stack as behaviour

Post by kaveh1000 » Tue Oct 15, 2019 12:52 pm

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:

Code: Select all

on openstack
   answer "hi"
end openstack
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.
Attachments
Minimal example.zip
(1.24 KiB) Downloaded 15 times
Kaveh

bogs
Posts: 4196
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using external script only stack as behaviour

Post by bogs » Tue Oct 15, 2019 1:39 pm

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.
missingScriptStack.png
Ummm.....which way did it go? which way did it go....
Once I added this -

Code: Select all

on preOpenStack
   start using stack "path/to/your/script/only/stack/script_stack.livecodescript"
end preOpenStack
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 :wink:
Image

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

Re: Using external script only stack as behaviour

Post by kaveh1000 » Tue Oct 15, 2019 2:26 pm

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. :-)

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
Thanks again as ever...

Kaveh
Kaveh

bogs
Posts: 4196
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using external script only stack as behaviour

Post by bogs » Tue Oct 15, 2019 2:38 pm

kaveh1000 wrote:
Tue Oct 15, 2019 2:26 pm
I thought setting behaviour through the interface and having the script stack in the same directory would be sufficient.
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 :wink:

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.
Image

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

Re: Using external script only stack as behaviour

Post by dunbarx » Tue Oct 15, 2019 2:56 pm

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

Klaus
Posts: 11495
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Using external script only stack as behaviour

Post by Klaus » Tue Oct 15, 2019 3:34 pm

kaveh1000 wrote:
Tue Oct 15, 2019 2:26 pm

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
Since we have very nice SPECIALFOLDERPATH() codes, there is really no need to mess around with the defaultfolder! 8)
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
This may not help you with the actual problem, sorry.
But the dictionary is no help here and needs to be updated for scriptonly stacks a behavior.

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

Re: Using external script only stack as behaviour

Post by kaveh1000 » Tue Oct 15, 2019 3:40 pm

Thanks Klaus. I knew that was not the ideal way and I will use your code.
Kaveh

Klaus
Posts: 11495
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Using external script only stack as behaviour

Post by Klaus » Tue Oct 15, 2019 3:48 pm

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! :D

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

Re: Using external script only stack as behaviour

Post by kaveh1000 » Tue Oct 15, 2019 3:50 pm

Great. I remember you helped me with "copy files" before. :-)
Kaveh

bogs
Posts: 4196
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using external script only stack as behaviour

Post by bogs » Tue Oct 15, 2019 4:10 pm

dunbarx wrote:
Tue Oct 15, 2019 2:56 pm
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?
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.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5225
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using external script only stack as behaviour

Post by jacque » Tue Oct 15, 2019 5:07 pm

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

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

Re: Using external script only stack as behaviour

Post by dunbarx » Tue Oct 15, 2019 6:46 pm

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

bogs
Posts: 4196
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using external script only stack as behaviour

Post by bogs » Tue Oct 15, 2019 7:46 pm

Hey Craig,

I did say -
bogs wrote:
Tue Oct 15, 2019 2:38 pm
I don't use script only stacks (or behaviors, for that matter), and so am hardly the best qualified to answer about their intricacies.
- earlier :wink:

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.
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2234
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Using external script only stack as behaviour

Post by [-hh] » Tue Oct 15, 2019 10:27 pm

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.
shiftLock happens

Post Reply

Return to “Talking LiveCode”