Page 1 of 1
Add or delete a new card from a button.
Posted: Fri Mar 05, 2010 10:03 pm
by benco5000
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
Re: Add or delete a new card from a button.
Posted: Fri Mar 05, 2010 11:31 pm
by bn
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
Re: Add or delete a new card from a button.
Posted: Sat Mar 06, 2010 12:43 am
by Regulae
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
Re: Add or delete a new card from a button.
Posted: Sat Mar 06, 2010 1:02 am
by bn
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
Re: Add or delete a new card from a button.
Posted: Sat Mar 06, 2010 1:50 am
by Regulae
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