A code to destroy the value of a variable
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
A code to destroy the value of a variable
Hi everyone
I have a question , I noticed that when I use a variable to count the score of clicks of different objects . The value of the score that uses variable whether it was a global or a local variable maintain its value of the score that has reached and continues to count from that point even when I close and re-open the app and I reset the variable value to 0 with code (put 0 into _gScorePlayer ) for example when a user reaches score 15 and closes the app , next time the score continues from 15 and so on
I am a beginner in livecode
Thanks fro your continues help and support guys
I have a question , I noticed that when I use a variable to count the score of clicks of different objects . The value of the score that uses variable whether it was a global or a local variable maintain its value of the score that has reached and continues to count from that point even when I close and re-open the app and I reset the variable value to 0 with code (put 0 into _gScorePlayer ) for example when a user reaches score 15 and closes the app , next time the score continues from 15 and so on
I am a beginner in livecode
Thanks fro your continues help and support guys
-
- Livecode Opensource Backer
- Posts: 9287
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: A code to destroy the value of a variable
A variable should clear its value when you QUIT LiveCode; if you only CLOSE the stack
the variable may remain in the computer's memory: and, if you REOPEN the stack
before QUITTING LiveCode what you describe may happen.
the variable may remain in the computer's memory: and, if you REOPEN the stack
before QUITTING LiveCode what you describe may happen.
Re: A code to destroy the value of a variable
Ok thank yourichmond62 wrote: ↑Tue May 12, 2020 9:14 pmA variable should clear its value when you QUIT LiveCode; if you only CLOSE the stack
the variable may remain in the computer's memory: and, if you REOPEN the stack
before QUITTING LiveCode what you describe may happen.
I will make sure that I close/exit the entire livecode program then re-open my app again
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: A code to destroy the value of a variable
Hi.
Read about the "closeStack" message, which you can use here. That message is sent regardless of whether you close the stack or quit LiveCode entirely. Create a handler that resets the counter (pseudo):
Craig
Read about the "closeStack" message, which you can use here. That message is sent regardless of whether you close the stack or quit LiveCode entirely. Create a handler that resets the counter (pseudo):
Code: Select all
on closeStack
put 0 into yourCounterVariable
save this stack
end closeStack
Re: A code to destroy the value of a variable
Oh thank you will do this toodunbarx wrote: ↑Tue May 12, 2020 9:40 pmHi.
Read about the "closeStack" message, which you can use here. That message is sent regardless of whether you close the stack or quit LiveCode entirely. Create a handler that resets the counter (pseudo):CraigCode: Select all
on closeStack put 0 into yourCounterVariable save this stack end closeStack
but where do I write this code , in the script of what ?
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: A code to destroy the value of a variable
Hi.
The stack script is the place for such things. But here is homework for you.
Would it also work in the card script? What if your stack had more than one card? Why do I ask these sorts of things?
Craig
The stack script is the place for such things. But here is homework for you.
Would it also work in the card script? What if your stack had more than one card? Why do I ask these sorts of things?
Craig
Last edited by dunbarx on Wed May 13, 2020 1:45 pm, edited 1 time in total.
Re: A code to destroy the value of a variable
Hi Linda,
Not sure to understand, but in case what you called your app
is a stack you're executing in the IDE, then you have nothing to do except
uncheck "Variable Preservation" in the IDE Preferences:
HTH,
Thierry
Not sure to understand, but in case what you called your app
is a stack you're executing in the IDE, then you have nothing to do except
uncheck "Variable Preservation" in the IDE Preferences:
HTH,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: A code to destroy the value of a variable
Another way is to set the destroystack of the stack to true. You can do that in the property inspector. Then when you close the stack, everything is removed from memory including all variable values (except global variables, which is why I don't use them.) You don't need any code with this method.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: A code to destroy the value of a variable
You can delete a variable with the "delete variable" command, e.g.:
https://livecode.com/resources/api/#liv ... e_variable
Code: Select all
delete variable tMyVarName
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: A code to destroy the value of a variable
Thank you for your help
I think with my very little experience , it would work but not if I had more than just one card as you mentioned
And you are telling me this you to help me think more about it , maybe
Re: A code to destroy the value of a variable
Thank you so much guys for your help
really appreciate it
Wow you all answered different solutions you are really legends in livecode
really appreciate it
Wow you all answered different solutions you are really legends in livecode
-
- VIP Livecode Opensource Backer
- Posts: 9579
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: A code to destroy the value of a variable
Lina.
I find doing such things indispensable, whether for small gadgets like the one you brought up, or tests within a large project to prove or disprove one idea or another. I make these sorts of things all day. I do it for fun.
Craig
I was wondering if you were the type of person who would make a test stack with a few small handlers and try it.I think with my very little experience , it would work but not if I had more than just one card as you mentioned
And you are telling me this you to help me think more about it , maybe
I find doing such things indispensable, whether for small gadgets like the one you brought up, or tests within a large project to prove or disprove one idea or another. I make these sorts of things all day. I do it for fun.
Craig