Advice on variable scopes

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
alexGAzLSp
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Wed Dec 07, 2011 1:39 pm

Advice on variable scopes

Post by alexGAzLSp » Thu Oct 11, 2012 1:11 am

Hi, I'm seeking advice on a technique I'm using as an alternative with virtual custom properties to global variables and some problems I'm having with this approach. I got this idea from one of the lessons. I'm creating a sub-stack called 'globals' as part of my application. This 'globals' stack has scripting like:

local _variable
setProp uVariable pValue
put pValue into _variable
end uVariable

getProp uVariable
return _variable
end uVariable

My problem is that the local variables of this sub-stack don't seem to hold their values when I'm shifting between design and runtime, whereas other variables and fields seem to. My application consists of a main stack and a number of cards with my sub-stacks and those of 3rd party products as well.

Perhaps I'm going the wrong way of dealing with this. I'd appreciate any advice. Alex

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Advice on variable scopes

Post by dunbarx » Thu Oct 11, 2012 2:07 am

Hi,

When you say "don't hold their value", do you mean when you navigate to the main stack? Local variables will not do that. In fact, that is what custom properties are good at, or global variables if you want.

Your code seems fine otherwise.

I wonder if it is necessary to have an entire stack just to hold information? I would rethink that aspect first of all. And do you really need substacks? You might, but write back if I am missing what you mean.

Craig Newman

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”