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
Advice on variable scopes
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 14
- Joined: Wed Dec 07, 2011 1:39 pm
-
- VIP Livecode Opensource Backer
- Posts: 9660
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Advice on variable scopes
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
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