Local mutiny .... (=^‥^=)

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

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Local mutiny .... (=^‥^=)

Post by Mariasole » Thu Jul 06, 2017 3:06 pm

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... :roll:


I'll explain: :mrgreen:

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
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Local mutiny .... (=^‥^=)

Post by Klaus » Thu Jul 06, 2017 3:21 pm

Hi Maria,

maybe you could make a repeat loop through "the localNames"?


Best

Brother Klaus

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Local mutiny .... (=^‥^=)

Post by [-hh] » Thu Jul 06, 2017 3:25 pm

Hi niece Mariasole,

see dictionary > delete variable.
When putting empty into a variable it still exists, is only empty.

Uncle Hermann
shiftLock happens

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Local mutiny .... (=^‥^=)

Post by Mark » Thu Jul 06, 2017 3:36 pm

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.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Local mutiny .... (=^‥^=)

Post by [-hh] » Thu Jul 06, 2017 3:40 pm

Mark wrote: delete variable ... doesn't seem to work correctly
Could you give an example that doesn't work correctly?
shiftLock happens

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: Local mutiny .... (=^‥^=)

Post by Mariasole » Thu Jul 06, 2017 3:57 pm

Thank you guys!
I think I was wrong!
For "delete" I mean "emptying". :D
I'm looking for a way to clear all variables without rewrite them!
I do not know if I can explain it!
Damned Babylon! :twisted:


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... :wink:

;)
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Local mutiny .... (=^‥^=)

Post by Mark » Thu Jul 06, 2017 4:12 pm

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.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Local mutiny .... (=^‥^=)

Post by FourthWorld » Thu Jul 06, 2017 6:50 pm

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:

Code: Select all

delete variable tA
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: Local mutiny .... (=^‥^=)

Post by Mariasole » Fri Jul 07, 2017 8:51 am

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. :oops:

My case is another case. Beware, it's an imaginary case (!) so I can explain what I want. 8)

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!) :P

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 :wink: )!

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! :shock:

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. :x

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). :o

:shock:

:?

:roll:

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! :wink:


Mariasole
(=^‥^=)
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Local mutiny .... (=^‥^=)

Post by Klaus » Fri Jul 07, 2017 9:56 am

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

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Local mutiny .... (=^‥^=)

Post by MaxV » Fri Jul 07, 2017 1:32 pm

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
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Local mutiny .... (=^‥^=)

Post by Klaus » Fri Jul 07, 2017 1:38 pm

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"! :D

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: Local mutiny .... (=^‥^=)

Post by Mariasole » Fri Jul 07, 2017 4:21 pm

Brother Klaus!
Thank you for your valuable help!
I also read the dictionary, but in my head I can not understand! :oops:
It always tells uncle Tony that I have a hard head like a leather drum! :lol:
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! :?
Attachments
Mariasole.zip
(1.17 KiB) Downloaded 175 times
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Local mutiny .... (=^‥^=)

Post by MaxV » Fri Jul 07, 2017 4:45 pm

Mariasole, consider this:
local/global variable = bad
custom properties = good
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Local mutiny .... (=^‥^=)

Post by SparkOut » Fri Jul 07, 2017 7:39 pm

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.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”