local tCurrentValue

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Posts: 16
Joined: Thu Dec 08, 2011 12:20 pm

local tCurrentValue

Post by dimen426GA1Hmj » Thu Aug 04, 2016 9:59 am

I tried removing the line in the percentPressed command script “local tCurrentValue” and the program executed just fine. My question is, was this line added as part of “good programming practice” or is there some practical reason for adding this code. For a newbie all I see is one additional line of code which I can do away with, making the code more efficient...or is it? When would you recommend adding the local variable and when would you not have to. Why would it make sense to add this to this particular script and this particular app now that I don't see any difference in the result.

VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4873
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN

Re: local tCurrentValue

Post by jacque » Thu Aug 04, 2016 5:51 pm

It's required if you are running with explicit variables turned on, which helps catch some typos in scripts. In some circles it's considered good programming practice as well, especially by those coming from other languages where it's required. I never debug with explicit variables so I don't include the declarations. It's mostly a matter of personal preference though it has been known to cause religious wars occasionally.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Posts: 1
Joined: Wed Feb 13, 2019 5:18 pm

Re: local tCurrentValue

Post by 6zayn » Wed Feb 13, 2019 5:26 pm

Don't run it with explicit variables. It gets stuck.
VMate 9apps
Last edited by 6zayn on Wed Feb 20, 2019 9:06 pm, edited 1 time in total.

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

Re: local tCurrentValue

Post by FourthWorld » Wed Feb 13, 2019 6:31 pm

The only difference would be if the declaration is outside of a handler or inside. Outside is needed if you want the variable to be available to all handlers within the script. Inside is not necessary, used by some scripters for clarity.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Calculator”