Best way to include stack1 in another stack

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Best way to include stack1 in another stack

Post by dntknwjck » Fri Feb 21, 2020 6:33 pm

Hello
Need some help with including separate stacks and cards in a new stack.
For example I have a stack that creates a calendar that picks the day that was clicked on, (in a data grid). That I want to use in another stack as a picker.
Tried "start using stack" but could not make that work also tried copying the objects from one stack to the other one, but I don't want to multiple copies work with.

There is probably an easy way to do this but I haven't been able to find it.

Thanks

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

Re: Best way to include stack1 in another stack

Post by Klaus » Fri Feb 21, 2020 6:39 pm

Hi dntknwjck,

every object is bound to ONE stack, so this is not possible without copying,
if I understood you correctly.

However copying data from one stack (datagrid) to another is a snap! :D


Best

Klaus

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

Re: Best way to include stack1 in another stack

Post by dunbarx » Fri Feb 21, 2020 8:50 pm

Hi.

If I understand what you are trying to do, the problem is not accessing the controls of one stack from another, it is that certain controls, that is, the table field and the dataGrid, are difficult to access that way. Here is an experiment that you might find useful if you want to try to kluge this. Make two new stacks. Name one "xxx" and the other "yyy". In stack "xxx" make a button and name it "b1". In stack "yyy" make a button and name it "b2".

In the script of btn "b1:

Code: Select all

on mouseUp
   set the clipBoardData to random(999)
end mouseUp
In the script of btn "b2":

Code: Select all

on mouseUp
   send "mouseUp" to btn "b1" of stack "xxx"
 --  click at the loc of btn "b1" of stack "xxx" -- ANOTHER WAY
   answer the clipBoardData
end mouseUpp
Works fine; you get a number every time you click on "b2". Either line above will do the trick.

But from what I said above, it is not easy to click at some loc of either of those two controls. You do not get the response you want. The dataGrid especially only likes direct mouse clicks. It does a lot with that simple action. There are kluges discussed here about ways to fool it.

But you might try your own kluge. Write back if you do.

Craig

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Re: Best way to include stack1 in another stack

Post by dntknwjck » Mon Mar 02, 2020 10:34 pm

Craig
Thanks for the example. That is not exactly what I am trying to do. I guess my original question was not clear.

I have built a calendar using a DataGrid to use as a date picker. At this time I have a main stack and a subStack with the calendar on the subStack.

I know I could rename this and continue on with my project but then I end up with the same code in several places and maintenance becomes a problem.
Is there a way to reuse or import the original subStack into another application?

I know this can be done with script using a script only stack.

I have tried to copy and past but that doesn't work well with the DataGrid haven't tried cloning, but see from some posts that doesn't work well either.

Terry

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

Re: Best way to include stack1 in another stack

Post by dunbarx » Mon Mar 02, 2020 11:12 pm

Hi.

Why do you have two stacks? Is one a "splash" stack that becomes the executable when making standalones?

As for getting code in one place, accessible from many other places, there are several techniques. These include creating library stacks, using behaviors, or sending certain scripts "to back". These all depend on what you want achieve.

Craig

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Re: Best way to include stack1 in another stack

Post by dntknwjck » Tue Mar 03, 2020 12:58 am

Hi
Used two stacks to develop the calendar and interface. From previous platforms I have used I have been able to import things like this and assumed that to be the case with LiveCode. Appears I was wrong.

Can something like this be put in a library and be reused? If so can you point me to some place that has explanations and examples on how to build and use libraries.

Terry

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

Re: Best way to include stack1 in another stack

Post by dunbarx » Tue Mar 03, 2020 2:50 am

Used two stacks to develop the calendar and interface.
OK. Whatever. (and I am not being snarky)
assumed that to be the case with LiveCode. Appears I was wrong.
Certainly you can, though perhaps "import" is not the right term in the LC world.

Exploiting the message hierarchy is the principal native method to set up stacks that allow messages to "funnel" through them, usually "above" or "after" everything else contained in your app and its environs. You can also "insert" a single script, of any kind, "into back", where it, too, will receive messages after everything else does. Further, behaviors are supported in the quest to make LC more object oriented, and these are explicitly designated button or stack scripts that receive messages from other objects that point to them.

In short, yes, you can establish all the tools you need to do what you want.

A question at the most basic level. Do you know how to place, say, a "mouseUp" handler in the card script in such a way that any number of buttons on that card can use that handler? And that each of those buttons can be identified by the overarching handler so that each button can do its own thing?

Craig
Last edited by dunbarx on Tue Mar 03, 2020 2:51 pm, edited 1 time in total.

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

Re: Best way to include stack1 in another stack

Post by bogs » Tue Mar 03, 2020 11:22 am

Heya Terry,

To answer what seems like your most likely way to go,
dntknwjck wrote:
Tue Mar 03, 2020 12:58 am
can you point me to some place that has explanations and examples on how to build and use libraries.
check http://livecode.byu.edu/messages/libraries.php

I'm not sure why you wouldn't be able to just set your substack as it's own stack and issue a 'start using stack [your stack]' as you indicated in your first post, unless it was because it was a substack of another stack. Someone that knows better may be able to say for sure.
Image

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Re: Best way to include stack1 in another stack

Post by dntknwjck » Tue Mar 03, 2020 3:57 pm

Thanks Bogs, that was exactly what I was looking for.

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

Re: Best way to include stack1 in another stack

Post by dunbarx » Tue Mar 03, 2020 4:45 pm

Exploiting the message hierarchy is the principal native method to set up stacks that allow messages to "funnel" through them, usually "above" or "after" everything else contained in your app and its environs.
"Start using", as bogs explicitly mentioned, is how one does this. You can think of stacks "in use" as library stacks. These are placed near the very end of the hierarchy. But it is the hierarchy, and comfort in its use, that you simply must start practicing with.

For the other methods, you need to explore the "insert script" command, and then read a bit about behaviors:
http://lessons.livecode.com/m/4071/l/69 ... a-behavior
This and its related lessons...

Craig

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Best way to include stack1 in another stack

Post by AxWald » Tue Mar 03, 2020 6:50 pm

Hi,

Still a good example how to do it: Sarah Reichelt's Calendar

Basically, your calendar is a separate stack. You call it:

Code: Select all

go to stack Calendar as modal
Now you're in the Calendar stack, and when you're done selecting, do there:

Code: Select all

set the dialogdata to "whatEverYouWantToReturn"
close this window
Back at the caller stack, right after the first line at top, you:

Code: Select all

put the dialogdata into theDate
Bingo.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

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

Re: Best way to include stack1 in another stack

Post by bogs » Tue Mar 03, 2020 9:04 pm

Definitely worth looking at, nicely put together.
Image

dntknwjck
Posts: 24
Joined: Sat Mar 23, 2019 6:14 pm

Re: Best way to include stack1 in another stack (DatePicker)

Post by dntknwjck » Thu Mar 05, 2020 5:04 pm

Thanks to all.
The information from AxWald was the final piece to make this work.
After I get things cleaned up I will post the code. It may be helpful to others.

DtPicker is a calendar Date Picker Example

I forgot how much fun it is to be a "Newbe"

Terry


DtPicker.zip posted 3/10/2020
Attachments
DtPicker.zip
(10.92 KiB) Downloaded 171 times

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”