Constant statement limitations.

Alex Tweedly alex at tweedly.net
Tue May 29 05:02:00 EDT 2012


Thanks Igor, but you're talking about where constants can be declared; I 
was talking about where they can be used.

I read the dictionary the same way you do, in the context of declaration 
(constants can be declared within or outwith handlers, with different 
context). And I agree with Mark that redefining a constant is a bad idea.

But neither of those was my issue - in my reply to Craig I did what I 
should have done in the first place and included a complete script 
showing the problem. Constants that have been properly, globally 
declared can be used within handlers but do not take effect outside 
handlers.

So in a revserver that is "just one big script" you cannot use the 
constants except within any handlers.

-- Alex.

On 29/05/2012 05:51, Igor de Oliveira Couto wrote:
> Alex, I don't know if you and I are reading the dictionary in the same way:
>
> On 29/05/2012, at 9:00 AM, Alex Tweedly wrote:
>
> [...]
>
>> The dictionary entry for constant says:
>>> If you place the constant statement in a handler, you can use the constant anywhere in the handler. If you place the constant statement in a script outside any handler, you can use the constant anywhere in the handlers of that script.
>> NB - "can use the constant anywhere *in the handlers* of that script".
>>
>> That was a reasonable limitation in traditional Livecode - but seems less reasonable in the context of revserver.
> [...]
>
> I *think* what the dictionary means - and please someone correct me if I'm wrong - is that there are 2 ways to declare a constant value: INSIDE a handler (like inside a mouseUp, enterField, etc.), or OUTSIDE any handlers (the same way you'd declare a SCRIPT VARIABLE). The 2 ways would be like this:
>
> INSIDE A HANDLER
>
> on enterField
>     constant kIncrease = 3
>     answer kIncrease
> end enterField
>
> The problem with declaring the constant that way, is that it is defined only for THAT specific 'enterField' handler. If you also had a second handler that expected to use that value, such as...:
>
> on closeField
>     answer kIncrease
> end closeField
>
> ...that would fail, because 'kIncrease' is defined only inside 'enterField'. To overcome that, you can declare the constant like this:
>
>
> OUTSIDE HANDLERS
>
> contant kIncrease = 3
>
> on enterField
>     answer kIncrease
> end enterField
>
> on exitField
>     answer kIncrease
> end exitField
>
> ...would work, as 'kIncrease' will now be available to *all* handlers.
>
> In the context of revServer, this still applies. For instance: if your revServer application is just one big script - ie., a 'main' script that 'includes' or 'requires' others (which is, in effect, the same as having one long script) - then a constant declaration outside all handlers will in effect make it a global constant.
>
> I hope this helps!
>
> --
> Igor Couto
> Sydney, Australia
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>





More information about the use-livecode mailing list