Cloning cards causing many copies to show up in Project Browser

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
standgale
Posts: 26
Joined: Fri May 07, 2021 4:12 am

Cloning cards causing many copies to show up in Project Browser

Post by standgale » Fri May 21, 2021 4:00 am

Hi,

I am writing what is essentially a survey, with a small number of different cards used as templates, to be duplicated and populated with different data.
I am cloning the card, storing the ids of the cloned cards in an array, and using the array to navigate back and forth through the cards. This works fine.

What is a problem is that these cloned cards are showing up in the project browser seemingly at random. If I run the program, they are not there. I do a few more things and some cards show up. I quit without saving, re-open the livecode project, and now there are even more cards. I delete them and save, reopen, and they, or different ones, reappear.

Is there some way to avoid this, or is it just some weird flaw with cloning cards and so I should abandon the idea altogether?
If I do abandon the idea of cloning the cards, I will instead just have a small set of template cards which I keep reusing and populating with different data. This would work fine but the idea of actually creating and moving through the cards seemed like such a nice idea. If cloning the cards is not going to work out, I would also take any suggestions on nice ways to implement this type of application in an appropriately livecode-esque way.

Using windows 10 Enterprise, Livecode Indy 9. 6

Code for cloning is in preOpenStack and pretty simple:
clone card cardTextOnly
--code here to put some stuff in the fields of "it" the new card
put the id of it into gCardList[tCardCount] --the array of cards I'm using to navigate

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

Re: Cloning cards causing many copies to show up in Project Browser

Post by dunbarx » Fri May 21, 2021 4:18 am

Hi.

I hardly ever use the Project Browser.

Know however, that all open stacks that are in memory (not just currently open) and all their child objects are displayed, not just the one you are working on. Is it possible that these spurious objects belong elsewhere?

But I cannot imagine that some living objects disappear from the PB.

Craig

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

Re: Cloning cards causing many copies to show up in Project Browser

Post by bogs » Fri May 21, 2021 10:04 am

I'm not entirely sure I understand where the problem is from your description.

Some thoughts I had reading it though were:

1. Any object names (card, control, stack, etc) should be quoted in code ~
clone card "cardTextOnly"
~however this is not causing your problem.

2. You have this handler running in a preOpenStack, which means that any time the stack opens, you are going to clone the card "cardTextOnly", but of course, all of your cards are named "cardTextOnly". At the most basic level, I would expect this to produce at least 3 cards named "cardTextOnly" if you open the project 3 times in the IDE, say, when you change a line and close and reopen the stack.
Image

3. Lastly, how would the engine know which "cardTextOnly" you intended to clone?

I can think of several solutions off the top of my head if you want to open the stack and only wind up with 1 card text only showing up (or at least, be able to control how many are there).

One would be put the cloning code into a button's mouseUp instead of a preOpenStack area. Add a 2nd button to reset the stack by deleting all the cards after 1.

Another, if you insist on the preOpenStack placement would be to delete all the cards except the first on opening, *then* clone the card you want. This should guarantee that no matter how many times you close / open / load etc the stack, you will have exactly 1 cloned card of "cardTextOnly".

As to the Project Browser, I can't comment on the current iterations, but if either of the 2 suggestions doesn't bring the perceived problem to an end, you might consider filing a bug report.
Image

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

Re: Cloning cards causing many copies to show up in Project Browser

Post by jacque » Fri May 21, 2021 5:16 pm

A better place for the clone command would be when the user tries to navigate to the next card. I assume you have a button or similar to do that.

Cloning on preOpenStack will always create at least one cloned card on launch and if you don't delete it, you'll get more every time you open the stack.

If you see extra cards in the project browser, try refreshing it. It may have changed since I last used it, but in the past I had to close it and reopen it to update the contents.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”