Page 1 of 1
Deleting many cards in a loop
Posted: Sat Apr 05, 2014 3:25 pm
by atout66
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
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.
Re: Deleting many cards in a loop
Posted: Sat Apr 05, 2014 4:27 pm
by Klaus
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
...
Re: Deleting many cards in a loop
Posted: Sat Apr 05, 2014 4:32 pm
by Dixie
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...

Re: Deleting many cards in a loop
Posted: Sat Apr 05, 2014 5:04 pm
by atout66
@ 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".
BTW, this push and pop command seem usefull...
Thanks to all of you, I've learned some more pieces of code.
Kind regards.
Re: Deleting many cards in a loop
Posted: Sat Apr 05, 2014 5:30 pm
by Klaus
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
Re: Deleting many cards in a loop
Posted: Sat Apr 05, 2014 5:34 pm
by Dixie
LOL... re-tested mine too !... No problem here

Re: Deleting many cards in a loop
Posted: Sat Apr 05, 2014 6:09 pm
by atout66
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

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