Page 1 of 2
Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 3:06 pm
by Mariasole
Hi brothers and sisters!
Peace love and code!
I'm trying to figure out if you can do something with LC: delete ALL local variables without writing it again!
Obviously it will be easy, but I can not find the solution either on the manual or on the forum...
I'll explain:
Code: Select all
local aa
local bb
local cc
local dd
local ee
local ff
local gg
local hh
local ii
local ll
on mouseUp
// Loads the variables
put "sldfjdkj" into aa
put "sldfjdkj" into bb
put "sldfjdkj" into cc
put "sldfjdkj" into dd
put "sldfjdkj" into ee
put "sldfjdkj" into ff
put "sldfjdkj" into gg
put "sldfjdkj" into hh
put "sldfjdkj" into ii
put "sldfjdkj" into ll
put "sldfjdkj" into ZZ --->>>> This variable is not declared!
///////////////////////////////////////////////////////////
// CENSORED PART!
// TOP SECRET CODE CODE WORKING WITH THESE VARIABLES
///////////////////////////////////////////////////////////
// Deletes the variables at the end of the operation
put empty into aa
put empty into bb
put empty into cc
put empty into dd
put empty into ee
put empty into ff
put empty into gg
put empty into hh
put empty into ii
put empty into ll
put empty into ZZ --->>>>
end mouseUp
There is a way to say to LC:
Code: Select all
put empty into ALL local variables // All.... Including those not declared [ZZ]
Thanks to all friends in the world! Love at all!
Mariasole
(=^‥^=)
Re: Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 3:21 pm
by Klaus
Hi Maria,
maybe you could make a repeat loop through "the localNames"?
Best
Brother Klaus
Re: Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 3:25 pm
by [-hh]
Hi niece Mariasole,
see dictionary > delete variable.
When putting empty into a variable it still exists, is only empty.
Uncle Hermann
Re: Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 3:36 pm
by Mark
Put emtpy into xx doesn't destroy the variable. It just makes it empty. Delete variable xx should destroy the variable, but it doesn't seem to work correctly.
Re: Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 3:40 pm
by [-hh]
Mark wrote: delete variable ... doesn't seem to work correctly
Could you give an example that doesn't work correctly?
Re: Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 3:57 pm
by Mariasole
Thank you guys!
I think I was wrong!
For "delete" I mean "emptying".
I'm looking for a way to clear all variables without rewrite them!
I do not know if I can explain it!
Damned Babylon!
I would like to avoid rewriting
put empty into aa
put empty into bb
put empty into cc
put empty into dd
put empty into ee
put empty into ff
put empty into gg
put empty into hh
put empty into ii
put empty into ll
put empty into ZZ --->>>>
Also why, if a script was made a long time ago and the variables have not been all stated above (local aa, ecc.), it's a job to find them again (es ZZ).
So I thought: There is a command to say LC:
put empty on ALL local variables That I do not even remember what and where they are...

(=^‥^=)
Re: Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 4:12 pm
by Mark
Is this what you're looking for?
Code: Select all
put the variableNames into myList
repeat for each item myItem in myList
put "put empty into" && myItem into myTempScript
do myTempScript
end repeat
If you're careful with naming your variables, you could do something like
Code: Select all
repeat for each item myItem in myList
if char 1 to 3 of myItem is "abc" then
put "put empty into" && myItem into myTempScript
do myTempScript
end if
end repeat
For your purpose, it might be better to use an array. Putting empty into the array variable will clear all its elements.
Re: Local mutiny .... (=^‥^=)
Posted: Thu Jul 06, 2017 6:50 pm
by FourthWorld
A large number of variables on which you need to perform similar actions is often a natural fit for storage in an array:
Code: Select all
put "foo" into tA["aa"]
put "bar" into tA["bb"]
To delete:
Re: Local mutiny .... (=^‥^=)
Posted: Fri Jul 07, 2017 8:51 am
by Mariasole
Thanks for your help brothers (and sisters?)
But these solutions are
perfect for a project built to have variables called "regular" and "scheduled" (es.: aa, bb, cc... or t1, t2, t3)... I do not know if I explain.
My case is another case. Beware, it's an imaginary case (!) so I can explain what I want.
A) My uncle (Tony) gave me a very long and quite complex code.
B) My uncle Tony has made me a beautiful program to play stick bass by hitting the computer screen with pencils (with rubber on top!)
C) Uncle Tony is not very experienced with programming, he is a great artist and for him computers are used for create art, so Tony use LIVE CODE!!!!. The only programming language for artists (after Hypercard

)!
D) I've tried to "play" with this stick-bass-lcd-pencil-program, but because of a lack of memory management it needs a little retouch: put "empty" in all local variables at the end of code!
E) Unfortunately uncle Tony did not declare the variables, and they are called absurdly. Some examples: tyf; Ksdjfh; KingCr;Peter;PapaBear; akjsdh; ChapmanC; utr; ert; w;tw;BrotherKlaus;Chapmann; Chapmann; uuuuuuuuu; uuuuuuuuuuuuuuuuurgh ... etc.
F) To put empty in each variable then I should
line by line to understand what they are, isolate them from the code and then hand write: etc.
es:
Code: Select all
put empty into BrotherKlaus
put empty into Chapmann
put empty into ert
put empty into uuuuuuuuuuuuuuuuurgh
G) Uncle Uncle Tony wrote, apparently,
7475 variables (it seems that the number was directly advised by uncle Robert (Fripp).
Now I have asked myself: there is a code to say to LiveCode:
A) Do I obtain
a list of all local variables used in this script? (localNames()? Thanks Klaus! it's this one? how to use it?

)
B) Once I have this list I make (at end of the code) a loop to put "empty" on all 7475 variables.
And then I start playing with pencils on the screen thanks to the amazing program written by uncle Tony.
Thank you all for your patience!
I will be forever a beginner!
But always an artist!
Mariasole
(=^‥^=)
Re: Local mutiny .... (=^‥^=)
Posted: Fri Jul 07, 2017 9:56 am
by Klaus
Hi Sister,
put this into the script with the gazillion local variables:
Code: Select all
command clear_locals
put the localnames into tLocals
repeat for each line tLocal in tLocals
do ("put empty into" && tLocal)
end repeat
end clear_locals
So you can execute it from e.g. a button.
Best
Klaus
Re: Local mutiny .... (=^‥^=)
Posted: Fri Jul 07, 2017 1:32 pm
by MaxV
You can't delete local variables.
Use custom properties instead. They are more versatile, easy to clone/copy and delete.
Moreover you can't misunderstand them.
See
http://livecode.wikia.com/wiki/Custom_properties
Re: Local mutiny .... (=^‥^=)
Posted: Fri Jul 07, 2017 1:38 pm
by Klaus
Also good to know, from the dictionary about "local variable":
...
A variable that is accessible in only one handler and
whose existence ends when the handler stops executing.
...
So UNdeclared local variable should be gone after the handler they were used in ends.
Just like the messages for Mr. Ethan Hunt in "Mission impossible"!

Re: Local mutiny .... (=^‥^=)
Posted: Fri Jul 07, 2017 4:21 pm
by Mariasole
Brother Klaus!
Thank you for your valuable help!
I also read the dictionary, but in my head I can not understand!
It always tells uncle Tony that I have a hard head like a leather drum!
I give you an example in the attachment!
Mariasole
(=^‥^=)
PS:
Thanks Max, I will now also look at "custom properties" but I do not know what they are and how they work!

Re: Local mutiny .... (=^‥^=)
Posted: Fri Jul 07, 2017 4:45 pm
by MaxV
Mariasole, consider this:
local/global variable = bad
custom properties = good
Re: Local mutiny .... (=^‥^=)
Posted: Fri Jul 07, 2017 7:39 pm
by SparkOut
Cara Maria
What Uncle Tony has done is to declare the variable outside the handler, in the script of the object
This makes the variable not a local variable (to the handler) but a "script local" variable. If you had more handlers in the script of the button (as well as the mouseUp handler) then you would find that all handlers in that script have access to the same variable.
Now, that all makes sense to me.
But I thought that script local variables also lasted only while the script has active handlers. Declaring a local variable in the script has made it more like a global variable. I might be wrong, but this is not how I understood script local variables to behave, I didn't think script local variables maintained persistence, unless the checkbox in the Preferences under "Script Editor" for "Variable Preservation" is checked, but my system (Windows 10, LiveCode 9, DP-7) is showing persistence whether or not the checkbox is set in Preferences.