How do I erase graphics?

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller

Post Reply
Arndt
Posts: 2
Joined: Thu Jun 14, 2007 11:25 am
Location: Bonn, Germany
Contact:

How do I erase graphics?

Post by Arndt » Thu Jun 14, 2007 3:54 pm

Hello folks,

I am excited about Revolution Studio, and now I imported an old HyperCard stack for the first time.
Almost everything works fine (and I can fix the remaining problems), but after trying some time with different functions and searching the help engine, I gave up with this problem:

I want to erase all graphic objects (lines etc.) on a specific card automatically. In the Hypercard version, I used this handler:

on clearscreen
choose "select tool"
doMenu "Select all"
doMenu "Clear Picture"
end clearscreen

This doesn't work, even when I translate it to the syntax of RR.
There MUST be a solution. Does anybody know it?

Thanks a lot,

Arndt

xApple
Posts: 113
Joined: Wed Nov 29, 2006 10:21 pm
Location: Geneva

Post by xApple » Thu Jun 14, 2007 9:44 pm

In the stack script:

Code: Select all

getProp objects 
  repeat with x = 1 to number of controls of the target 
    put the long name of control x of the target & return after myList 
  end repeat 
  sort myList 
  return myList 
end objects 
Anywhere:

Code: Select all

on deleteAllObjOfCd cardNum
 put the objects of card cardNum into cardObjects 
  repeat for each line curObj in cardObjects
    delete  curObj
  end repeat
end deleteAllObjOfCd

Arndt
Posts: 2
Joined: Thu Jun 14, 2007 11:25 am
Location: Bonn, Germany
Contact:

???

Post by Arndt » Fri Jun 15, 2007 9:58 am

Dear xApple....

... sorry, but I am probably too stupid to understand your code and how to use it.
Do you have some explanations for me or even a simpler (more "intuitive") way for doing it?

Sorry for being a dummie,
Arndt

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Fri Jun 15, 2007 2:26 pm

Here's a maybe simpler to understand example (with bonus comments):

Code: Select all

on mouseUp
  --will run if you click on button containing the script
  lock screen
  --makes it run faster, remove for visual proofing
  put the number of graphics into theGraphsCount
  repeat with currentGraphic = theGraphsCount down to 1
    --will loop as many times as there are graphics
    if there is a graphic currentGraphic then
      --check if there really is a graphic currentGraphic (optional)
      delete graphic currentGraphic
      --removes the graphic
    end if
  end repeat
end mouseUp
--the 3 lines above end all the opened control structures
When I started beginning using loops to delete objects, I always tried to use "repeat for the number of graphics times". But that wouldn't work, and I had to make complicated workarounds. That is because it would delete a graphic, and that'd change the number of graphics. So after deleting half of them, it would try to delete non-existent graphics, and generate an error. The above example should work fine though, because it starts deleting at the top, and automatically subtracts one from the variable "currentCount".
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

jlally
Posts: 33
Joined: Wed Mar 21, 2012 6:48 pm
Location: Portland, OR USA
Contact:

Re: How do I erase graphics?

Post by jlally » Mon Jul 09, 2012 10:28 pm

Hello,

I'm wondering if there's an easy way to select (and ultimately delete) multiple buttons on a card by name? I'm not looking to delete *all* of the buttons on my card, just the ones that begin with "myButtonNamePrefix". I'm relatively new to LiveCode, and in other scripting languages, I'd just do something like this (using a "*" wildcard):

select "myButtonNamePrefix*"
delete selected

or more simply:

delete "myButtonNamePrefix*"

Any help would be greatly appreciated!

Thanks in advance,
John
Lodestone Animation, Inc.
Macaroni Art for iOS

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: How do I erase graphics?

Post by mwieder » Mon Jul 09, 2012 10:38 pm

John-

you'll have to resort to a repeat loop for this:

Code: Select all

put the number of buttons of this card into tCount
repeat with x=tCount down to 1
  if the short name of button x of this card begins with "myButtonNamePrefix" then
    delete button x of this card
  end if
end repeat

jlally
Posts: 33
Joined: Wed Mar 21, 2012 6:48 pm
Location: Portland, OR USA
Contact:

Re: How do I erase graphics?

Post by jlally » Mon Jul 09, 2012 10:55 pm

Cool - looks like that's going to work! :D

Thanks so much, mwieder!
Lodestone Animation, Inc.
Macaroni Art for iOS

Post Reply

Return to “Converting to LiveCode”