Resetting variables, cards, etc
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Resetting variables, cards, etc
Hi,
How can I reset the cards, variables, etc, to the basic state, as I set them up?
I mean after testing out my app, things don't reset when I get back to edit mode and it's a bit annoying that I have to put back everything by hand.
Thank you.
How can I reset the cards, variables, etc, to the basic state, as I set them up?
I mean after testing out my app, things don't reset when I get back to edit mode and it's a bit annoying that I have to put back everything by hand.
Thank you.
Re: Resetting variables, cards, etc
Hi ColeBKray ,
I think you need a initMyCard handler to use at preopencard
Bestregards
Jean-Marc
I think you need a initMyCard handler to use at preopencard
Bestregards
Jean-Marc
https://alternatic.ch
Re: Resetting variables, cards, etc
And how do I initalize the card? What code should I Put in?
Can you explain in more detail?
Sorry I'm a complete beginner.
Thank you.
Cole
Can you explain in more detail?
Sorry I'm a complete beginner.
Thank you.
Cole
Re: Resetting variables, cards, etc
Hi Cole,
I understand your cd can be changed by the user and there is a default state of this cd
For exemple, loc of obj if move, field content, state of btn etc....
You can save this default state, store it in a customprop of the cd or in a file
and restore the default state at preopencard.
You can even do what you asked about "initiate a card" in an other thread
Best regards
Jean-Marc
I understand your cd can be changed by the user and there is a default state of this cd
For exemple, loc of obj if move, field content, state of btn etc....
You can save this default state, store it in a customprop of the cd or in a file
and restore the default state at preopencard.
You can even do what you asked about "initiate a card" in an other thread

Best regards
Jean-Marc
https://alternatic.ch
Re: Resetting variables, cards, etc
OMG this seems complicated. LiveCode should have something built-in for this, like a menu "Save card state as", and then a command initCardState "CardStateName".
I'm still learning a lot of commands and features of LiveCode, so I'll get back to the documentation on how to save states of objects in a file, and then recall it from there, etc...
Anyway, thanks
I'm still learning a lot of commands and features of LiveCode, so I'll get back to the documentation on how to save states of objects in a file, and then recall it from there, etc...
Anyway, thanks

Re: Resetting variables, cards, etc
Actually it's very simple. The first question you must ask though is will the end user be working within LC or from a standalone. If it is a standalone then all fields will always revert to the state they were in when it was compiled and all variables will clear when the stack is newly opened. Since a standalone can not save itself it is kind of a built in default state. So on openstack you just reinitialize variables that are saved as custom properties, a text file, or a rev stack. Now I am sure that will bring up lots of questions on how to save, but I will let you try to figure that out yourself first. The fun is just beginning.
Re: Resetting variables, cards, etc
Hi Cole
)
There is a lot of ways to do that
The following script use customproperties of controls to reset the cd
Best
Jean-Marc
Sorry no "Save card state as" menu in LC but you can build it. Magice is right, that is very simple (in LiveCodeOMG this seems complicated.LiveCode should have something built-in for this, like a menu "Save card state as"

There is a lot of ways to do that
The following script use customproperties of controls to reset the cd
Code: Select all
on preopencard
InitCard
end preopencard
--•• restore default properties of the target controls
on InitCard
set the rect of image "myimage" to the uMyrect of image "myImage"
put the uContent of field "myField" into field "myField"
end InitCard
--•• save some properties of the target controls
on SaveStateCard
put the rect of image "myimage" into tRect
set the uMyrect of image "myImage" to tRect
put fld "myField" into tContFld
set the uContent of fld "myField" to tContFld
end SaveStateCard
Jean-Marc
https://alternatic.ch
Re: Resetting variables, cards, etc
Good to hear these, and thanks for the help, really great community here, fast, helpful, and friendly, I like that 

Re: Resetting variables, cards, etc
Hi guys,
I did what you suggested, but I'm running into problems.
I guessed that the preOpenCard is called when I go to the card, so I created a new card with a button "Start" that has 'go to card xy' where xy is the card that actually does the thing I'm working on, put some initializing stuff in the preOpenCard of the xy card, but it seems like nothing is happening.
Here's the code that I've put in the xy card script:
Actually, nothing from the script really happens. What am I doing wrong?
Thanks
I did what you suggested, but I'm running into problems.
I guessed that the preOpenCard is called when I go to the card, so I created a new card with a button "Start" that has 'go to card xy' where xy is the card that actually does the thing I'm working on, put some initializing stuff in the preOpenCard of the xy card, but it seems like nothing is happening.
Here's the code that I've put in the xy card script:
Code: Select all
on preOpenCard
set the width of templateField to 250
set the location of button "AddNew" to 200,150
repeat with i=1 to POVNum --The AddNew button creates fields with name "POV1", "POV2", etc...
--I want to delete these when starting
put "POV" & i into dField
delete field dField
end repeat
put 1 into POVNum
end preopencard
Thanks

Re: Resetting variables, cards, etc
Hi,
I don't see in your above script.
global POVNum
With what you have there POVNum is empty. (I'm guessing that you have it populated as a global)
Everywhere you use a global you have to state it, so even in a button you need:
The same with your card script and then they can share it.
Edit:
better no global to worry about.
Simon
I don't see in your above script.
global POVNum
With what you have there POVNum is empty. (I'm guessing that you have it populated as a global)
Everywhere you use a global you have to state it, so even in a button you need:
Code: Select all
global POVNum
on mouseUp
put 5 into POVNum
end mouseUp
Yes, you have to take LC very literally (sometimes).I guessed that the preOpenCard is called when I go to the card
Edit:
Code: Select all
repeat with i = 1 to the number of fields of this cd
if there is a field ("POV" & i) then delete fld ("POV" & i)
end repeat
Simon
Last edited by Simon on Wed Apr 24, 2013 11:29 pm, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Resetting variables, cards, etc
Hi Cole,
Are you sure the location of btn "aadNew" changed and field "POV1" exists ?
Best
Jean-Marc
Nothing is wrong for me.Actually, nothing from the script really happens. What am I doing wrong?
Are you sure the location of btn "aadNew" changed and field "POV1" exists ?
Best
Jean-Marc
https://alternatic.ch
Re: Resetting variables, cards, etc
Thank you guys, I made it work.