Script to delete unwanted cards.

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
CAsba
Posts: 423
Joined: Fri Sep 30, 2022 12:11 pm

Script to delete unwanted cards.

Post by CAsba » Thu May 15, 2025 1:07 pm

Hi,
My project includes setting up a new card by copying a card template, then renaming it. LC also creates, at the same time, another, similar card with an id number such as card id 5723439, which can be seen as listed in the project browser.
At a later point in my project the user may be wish to delete the card from the archive, and my project has the facility to do this, by referring to the renamed card's name.
However, the card with id number that was created is not deleted. (Of course, the user does not know or care about this, but the system is fuller with it.)
I tried to add code using wildcard to delete the card with the id number, but without success.

Code: Select all

delete card id *******
Any ideas how solve this ?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Script to delete unwanted cards.

Post by dunbarx » Thu May 15, 2025 1:29 pm

CAsba.

When you say "LC also creates..." what do you mean? LC does not do this on its own, so are you saying it does? What am I missing?

In other words, are you saying LC creates an extra card each time you explicitly make one?

Craig
Last edited by dunbarx on Thu May 15, 2025 1:50 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Script to delete unwanted cards.

Post by richmond62 » Thu May 15, 2025 1:43 pm

LC also creates, at the same time, another, similar card
well, it will ONLY do that if you have told it to.

A computer can do almost nothing (beyond sitting on a table and looking like a box with some odd holes in its front) unless you tell it to: and remember GIGO. 8)

CAsba
Posts: 423
Joined: Fri Sep 30, 2022 12:11 pm

Re: Script to delete unwanted cards.

Post by CAsba » Thu May 15, 2025 1:47 pm

I certainly haven't written any code to create tyhe second card; I imagined that it was some built in aspect of LC.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Script to delete unwanted cards.

Post by dunbarx » Thu May 15, 2025 1:49 pm

CAsba.

No.

You have to have done this somehow. Post your handler?

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Script to delete unwanted cards.

Post by Klaus » Thu May 15, 2025 2:10 pm

Yes, please post the script!

I just made a quick test and this worked as exspected:

Code: Select all

on mouseUp
   delete card id 1004
   
   ## May give a hint if it does NOT work, will be empty on success
   answer the result
end mouseUp
Maybe you can add the line "answer the result" and see if and what it will tell you.
Where and when do you call that script to delete?
We cannot delete a card that has an object on it while its script is running.

Best

Klaus

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Script to delete unwanted cards.

Post by stam » Thu May 15, 2025 3:42 pm

Why not iterate through all the cards in the stack and delete those where no name is given?

But I do echo Craig’s question, how/why are duplicate cards being created? Seems likely your card creation code has bug…

CAsba
Posts: 423
Joined: Fri Sep 30, 2022 12:11 pm

Re: Script to delete unwanted cards.

Post by CAsba » Thu May 15, 2025 8:42 pm

The script is

Code: Select all

 go to cd "template2"
   clone cd "template2"
   set the name of card "template2" to fld "d" of cd "start here"
   go to cd fld "d" of cd "start here"

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Script to delete unwanted cards.

Post by Klaus » Thu May 15, 2025 9:00 pm

Hi CAsba,

looks like you are NOT renaming the cd "template2" but the card you want to clone!?
Try this:

Code: Select all

...
## No need to GO there, we can clone the card anyway
## go to cd "template2"

## First put the new name into a variable!
## This elmininates extra typing and makes it easier to debug, if neccessary.
put fld "d" of cd "start here" into tNewCardName

## We can already add the new name for the clone to this command:
clone cd "template2" AS tNewCardName
go cd tNewCardName
...
This should eliminate the need of deleting unwanted cards.

P.S.
"wildcards" do not work with "delete"!

Best

Klaus

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: Script to delete unwanted cards.

Post by stam » Fri May 16, 2025 1:03 am

Klaus wrote:
Thu May 15, 2025 9:00 pm

Code: Select all

clone cd "template2" AS tNewCardName
Klaus is spot on - alternatively you can use the long ID generated for the new object by the clone command, which is stored in the 'it' variable, so you could use something like:

Code: Select all

clone card "template2"
set the short name of it to <new_name>
But personally would go with clone card as <new_name> as Klaus suggest, keeps things simpler...

CAsba
Posts: 423
Joined: Fri Sep 30, 2022 12:11 pm

Re: Script to delete unwanted cards.

Post by CAsba » Fri May 16, 2025 9:53 am

Many thanks both - good to know you're still here !

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Script to delete unwanted cards.

Post by Klaus » Fri May 16, 2025 9:54 am

You're welcome!

And I'm always here. :-)

Please tell us if this:

Code: Select all

clone cd "template2" AS tNewCardName
fixed the problem for you.

Post Reply