Can a constant be global?

David Burgun dburgun at dsl.pipex.com
Mon Mar 27 06:14:38 EST 2006


Hi,

As far as I know, constants are only valid in the current script.  
Globals are really "Global" but then they can't be initialized to a  
value when they are defined, which is why I assume constants can't be  
"Global".

The only way I have found to make constants "Global" is to make and  
use a Library Stack that becomes a sort of poor man's constant.  
Here's what I do:


ConstantLib - In the stack script

constant kConstant1 = "XXXXX"
constant kConstant2 = "12"

function kConstant1
return kConstant1
end kConstant1

function kConstant2
return kConstant2
end kConstant2


Then do a "start using ConstantLib" somewhere in the stack(s) that  
you want to "see" the constants and when you want to access one do this:

put kConstant1() into myValue

or

add kConstant2() to myNumber

or

get kConstant1

Hope this Helps
All the Best
Dave

On 27 Mar 2006, at 11:52, Graham Samuel wrote:

> This is another of those things that I've lived without for years -  
> I normally use globals to contain text strings which may change if  
> the human language of the app changes (what is the Welsh for  
> "Cancel"? - don't know, but I know someone who can tell me!), so  
> that all the values can be initialised in one handler when the app  
> starts up: but after all this time I thought I'd try using  
> constants instead.
>
> However neither the RR documentation nor my experiments seem to  
> suggest that there is a way of making constants global (i.e  
> constant). Can this really be true? If so, they have a crushing  
> disadvantage with respect to globals. After all, RR's own constants  
> are global. I guess I've missed something.
>
> Thanks to anyone who can dispel another of my clouds of ignorance.
>
> Graham
>
>
> ----------------------------------------
> Graham Samuel / The Living Fossil Co. / UK and France
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list