Resetting a card to saved on close card.

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Resetting a card to saved on close card.

Post by FireWorx » Mon Apr 30, 2012 6:42 am

Hi,
I have a fairly complex animation that changes the location of some img's, disables some buttons, etc. If the user leaves the card early in the middle of the animation I would like the card to be restored to its opening state on open card or before it closes the card. Just as if the stack was relaunched from its icon. I started trying to reset the state of all the objects but it began to get complicated. Is there an easy way to restore the card to its standalone saved state so that when I return to the card the animation can start again fresh? Thought about having a duplicate card in the stack and overwriting the card each time? Or I guess I could just not let the user leave until the anim is done and resets itself but that seems restrictive. Any better ideas?

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

Re: Resetting a card to saved on close card.

Post by BvG » Mon Apr 30, 2012 4:04 pm

One way is the "revert" command but that will reset the whole stack (not globals tho, if you need state information), however, that can produce a slight flash, so maybe not the best approach.

Another Idea would be to duplicate the stack or the card, and then delete the modified version when the user is done.
Various teststacks and stuff:
http://bjoernke.com

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7397
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Resetting a card to saved on close card.

Post by jacque » Mon Apr 30, 2012 6:42 pm

Another way is to store the info about each control in custom properties and then restore them when you need to. During devlopment, run a handler like this:

Code: Select all

on setupControls
  repeat with x = 1 to the number of controls
    set the cLoc of control x to the loc of control x
    set the cEnabled of control x to the enabled of control x
  end repeat
end setupControls
Place everything where you want it, and then run that from the message box. If you ever want to change the positions of objects, you'll need to run it again. This is used for development only.

In your active working code you do this:

Code: Select all

on resetControls
  lock screen
    repeat with x = 1 to the number of controls
      set the loc of control x to the cLoc of control x
      set the enabled of control x to the cEnabled of control x
    end repeat
  unlock screen
end resetControls
You can add other properties if you need them. You could also make these into a single custom property array instead of a bunch of individual properties if you want.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply