Reset all during testing

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
p.schelvis
Posts: 17
Joined: Wed Dec 04, 2013 1:52 pm

Reset all during testing

Post by p.schelvis » Wed Dec 04, 2013 2:07 pm

Hello, i am new in livecodeworld. I made a small application. I want to reset all variables as if it is the first run for this program. How do i do this?
Even wenn i close the application and close livecode. The next time i start livecode and load the application it has rembered the variables from the last run.
Help would be nice

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Reset all during testing

Post by Klaus » Wed Dec 04, 2013 2:29 pm

Hi p.schelvis,

1. welcome to the forum! :D

2. You need to do it manually/via script!
Create a handler named "init_my_stack" (or whatever you name it) and execute it when the stack opens.
Something like this:

Code: Select all

local var1,var2,var3
### or GLOBALS or custom properties or whatever you use...

on openstack
  init_my_stack
end openstack

command init_my_stack
  put EMPTY into var1
  put EMPTY into var2
  put "This is text..." into var3
  ### etc...
end init_my_stack
You get the picture...


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Reset all during testing

Post by FourthWorld » Wed Dec 04, 2013 2:49 pm

Variables exist only in memory, and go away with everything else in memory when the app quits. This is true of all programs. Rather than variables, do you mean custom properties or field contents?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

p.schelvis
Posts: 17
Joined: Wed Dec 04, 2013 1:52 pm

Re: Reset all during testing

Post by p.schelvis » Wed Dec 11, 2013 10:25 am

Hi Richard.

I am having trouble with the principle. I am used to Visual Basic. When in VB i develope a program and i run that program the start is always the same. When, for example, i create a button in that program in flight, the next time i run that program the button will not be there.

in lc it seems to be different. For example the next script:

on mouseUp
create button "button2"
end mouseUp

Every time i run this, there will be a button2 added. When i save the program, and open it later there will be many button2's.

Is this intended?. if that is true then it's hard for me to understand why for this principle is chosen.

With best regards, Peter

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Reset all during testing

Post by Simon » Wed Dec 11, 2013 10:50 am

Hi Peter,
Sure this will work in a standalone.
But in the IDE if you save it then there can be plenty of buttons named "button 2".

it's interesting what VB is doing (if what you say is correct).

e.g. If I create a new text file and write "This is new text" then save the file and close it, I'm not surprised that when I open the file again I see "This is new text". Isn't that you would expect?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

p.schelvis
Posts: 17
Joined: Wed Dec 04, 2013 1:52 pm

Re: Reset all during testing

Post by p.schelvis » Wed Dec 11, 2013 12:33 pm

Hi Simon,

There is een switch in my head that will not switch! No doubt it's my fault. But this is my problem:

When you 'save as standalone application...', you get an executable, for example test.exe in windows. If you run test.exe (see my example above) the program test.exe create a 'button2'. When i close the program test.exe and start it again, ther will not be a 'button2'.

When you run in the IDE, LiveCode does not react the same. It doesn't restart the program from scratch like the exe does.

y.s Peter

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Reset all during testing

Post by Klaus » Wed Dec 11, 2013 12:58 pm

Dag Peter,

a "standalone" cannot save itself, NEVER, on NO platform!

That is why it will always open in the state in which the stack (that turns into a standlaone) has been saved!
When you open a stack in the IDE, it opens in its last saved state (eventually with many buttons "button2" :D )

Whatever, this is the way Livecode works, get used to it 8)


Best

Klaus

p.schelvis
Posts: 17
Joined: Wed Dec 04, 2013 1:52 pm

Re: Reset all during testing

Post by p.schelvis » Wed Dec 11, 2013 2:50 pm

Hello all of you,

Thank you for all of the answers. I accept that this is the way Livecode works. I now have a "on reset-to-startposition" message where i clean up.
That works fine for me.

With kind regards,
Peter

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Reset all during testing

Post by FourthWorld » Wed Dec 11, 2013 3:33 pm

On the olden days many of us included a handler named "StripAndShip" in our mainstacks, which we'd run from the Message Box before building specifically to reset anything needed.

In the modern world LiveCode now provides a message for this: savingStandalone. This is send immediately before the building process when making a standalone, and is a good place to put any such cleanup routines.

Another message that may be worth knowing about is standaloneSaved, sent immediately after the build. This can be helpful for handling any additional tasks you may want to do on either the output standalone (such as triggering an installer-maker for a one-click build process), or even just restoring your work copy to some state you may find useful when developing.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply