Add or delete a new card from a button.

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
benco5000
Posts: 11
Joined: Fri Mar 05, 2010 9:51 pm

Add or delete a new card from a button.

Post by benco5000 » Fri Mar 05, 2010 10:03 pm

I'm new to RunRev, did some coding in HyperCard years ago. I've searched the docs but cant seem to find these two basic commands. Its got to be simple. Have two buttons, one adds a card one deletes. Already figured out the background issue.
Thanks in advance for your help and patience.

Code: Select all

on mouseUp
  howToAddACard
end mouseUp

on mouseUp
  howToDeleteThisCard
end mouseUp

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Add or delete a new card from a button.

Post by bn » Fri Mar 05, 2010 11:31 pm

Hi benco5000,
try:

Code: Select all

on mouseUp
   delete this card
end mouseUp
and

Code: Select all

on mouseUp
   create card
   -- set the name of last card to "myNewCard"  --optional
end mouseUp
regards
Bernd

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Add or delete a new card from a button.

Post by Regulae » Sat Mar 06, 2010 12:43 am

It’s worth adding that if the button to delete the card is on the card itself, in this case you need to use an “indirect” method to delete the card, having, in the button script:

Code: Select all

on mouseUp
   send "DeleteACard" to this stack in 0 seconds
end mouseUp
... with, in the stack script:

Code: Select all

on DeleteACard
   delete this card
end DeleteACard
The button, which is on the card, can’t delete the card directly, as this would delete the button as well, whose handler is still executing. Sending the instruction to the stack achieves the desired result. “in 0 seconds” ensures the message is sent to the stack immediately after the mouseUp finishes.

Regards,

Michael

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Add or delete a new card from a button.

Post by bn » Sat Mar 06, 2010 1:02 am

Hello Michael,
nice to hear from you.
Of course, I tested with a button inside a backgroundgroup since I just assumed that that is what benco5000 wanted.
for buttons in a background this might also be helpful

Code: Select all

on mouseUp
   if the number of cards > 1 then
      delete this card
   end if
end mouseUp
(because it is so much fun to delete cards I somehow managed to delete them all, well at least the background w/buttons was deleted and I ended up with a blank card)
regards
Bernd

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Add or delete a new card from a button.

Post by Regulae » Sat Mar 06, 2010 1:50 am

Indeed, Bernd, the question did suggest that the buttons would be in a background. As an old HyperCard person myself, Rev’s backgrounds were initially a little confusing, but are actually more versatile than in HyperCard. I just thought I’d mention the “on the card” case for general interest. We must have the same sense of fun- I too kept clicking my “Delete this card” button until they were all gone. Your adjustment would have saved me from myself.

Regards,

Michael

Post Reply