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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to