Deleting many cards in a loop

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
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Deleting many cards in a loop

Post by atout66 » Sat Apr 05, 2014 3:25 pm

Hi to all,

I'm trying to delete several cards in a repeat loop. I have no syntax error but when the script runs, I get an error message which says :
"(repeat: error in 'with' end condition expression), char 1" ???
My code is this one below:

Code: Select all

   lock screen
   repeat with bb = 1 to the number of card of this stack
      get name of last card of this stack
      if IT <> laLimiteToDelete then -- laLimiteToDelete is the name of a card from which I stop deleting
         delete last card of this stack
      end if
   end repeat
   unlock screen
I also tried with

Code: Select all

delete card IT of this stack
without success

I must say that I don't run the script from the last card of the stack, but from the first one.
The card "laLimiteToDelete" is the third one of the same stack.

Do you understand what's wrong with that code ?
Kind regards.
Discovering LiveCode Community 6.5.2.

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

Re: Deleting many cards in a loop

Post by Klaus » Sat Apr 05, 2014 4:27 pm

Not exactly sure what the problem is, but here a working script:

Code: Select all

...
  lock screen
  
  ## We cannot delete the card where the script is currently executing!
  put the short name of this cd into tThisCard
  
  ## plural: the num of cardS
  ##repeat with bb = 1 to the number of card of this stack
  repeat with bb = 1 to the number of CARDS

    ## no need to add "... of this stack" if the script is in THIS stack :-)
    
    ## You need to check the SHORT Name! "the name of cd ..." = card "name of card"
    put the short name of last card into tName
    
    ## Do not try to delete these 2 cards:
    if tName <> "laLimiteToDelete" AND tName <> tThisCard then
      ## object names ALWAYS INM QUOTES!!!
      delete last card
    end if
  end repeat
  unlock screen
...

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Deleting many cards in a loop

Post by Dixie » Sat Apr 05, 2014 4:32 pm

Let's say you have a stack with 10 cards in it... put a button on the first card of the stack that contains the script below

Code: Select all

on mouseUp
   lock screen
   push card
   
   repeat with count = the number of cards of this stack down to 2
      go card count of this stack
      delete card count of this stack
   end repeat
   
   pop card
   put the number of cards of this stack
end mouseUp
You will now only have 1 card in the stack and you will be back at the first card... :D

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Deleting many cards in a loop

Post by atout66 » Sat Apr 05, 2014 5:04 pm

@ Dixie: Your code works but make an error like:
"(Object: stack locked, or object's script is executing)

@ Klaus

Code: Select all

## object names ALWAYS INM QUOTES!!!
      delete last card -- return error message like the Dixie's one
Finally mine did the same as your codes when I turned the "card" to "cardS". :wink:
BTW, this push and pop command seem usefull...

Thanks to all of you, I've learned some more pieces of code.

Kind regards.
Discovering LiveCode Community 6.5.2.

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

Re: Deleting many cards in a loop

Post by Klaus » Sat Apr 05, 2014 5:30 pm

Bonsoir atout66,
atout66 wrote: @ Klaus

Code: Select all

...
delete last card -- return error message like the Dixie's one
...
well, I tested my script in a "mouseup" handler in a button and it worked as exspected!
Where did you put that handler?


Best

Klaus

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Deleting many cards in a loop

Post by Dixie » Sat Apr 05, 2014 5:34 pm

LOL... re-tested mine too !... No problem here :D

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Deleting many cards in a loop

Post by atout66 » Sat Apr 05, 2014 6:09 pm

I also put that handler in a mouseUp, in a button, in the first card of the main stack.

Finally the 3 scripts delete the cards but with this error message.
I use LC 6.5.2... may be ?

Never mind, for now, I'm fighting with creating cards in an other stack (this works :roll: ) and trying to create a field inside that new card (this doen't work :( ), but it's an other story I'll say in an other topic (may be my record for today, no ? I didn't count them !!!)

Kind regards.
Discovering LiveCode Community 6.5.2.

Post Reply