Testing for numerics

Ken Ray kray at sonsothunder.com
Mon Oct 9 18:06:37 EDT 2006


On 10/9/06 3:21 PM, "Robert Sneidar" <bobs at twft.com> wrote:

> Hi Ken. With all due respect, your example would only work if I
> declared the global inside a script (and therefore every script that
> uses it). And then it would put null into the global regardless of
> what was in it before. That would be disastrous.

Actually, I don't think you understand fully what I was getting at. I didn't
mean that you declare the global and put NULL into it *in every script*...
what I meant was that at the absolute beginning of execution (your first
preOpenStack, say), you declare all the globals and put NULL into them:

global gMyGlob1, gMyGlob2

on preOpenStack
  put null into gMyGlob1
  put null into gMyGlob2
  -- (etc.)
end preOpenStack

Then later on, you can check the global (all you'd need to do is declare the
global in the script that needs to check it - don't assign anything to it),
and if it is NULL then it means it hasn't been changed since it was
originally declared at the beginning of execution. If it was empty, it would
mean that somewhere along the line a script line set it to empty:

(script of a button on some stack):

global gMyGlob1

on mouseUp
  if gMyGlob1 = NULL then
    -- you know it has never had its value set since its original
    -- declaration
  else
    -- you know that *someone* changed the value of this global
    -- even if it is empty (i.e. "")
  end if
end mouseUp

> You might say I  
> could just check to see if anything was in it, but that leads us back
> to the original question, which is, how do I discern between a global
> that just got declared but has yet to have anything put into it, and
> a global that is simply empty at the moment. The answer of course, is
> you can't do that.

You're right, of course - there's no way to just declare a global and then
later try and tell the difference between it being newly declared and it
having had "empty" put into it.
 
> But thanks to all who wanted to help. I am just going to have to code
> around this by creating init flags throughout the code whenever a
> global was checked for null, and use those instead.

You can do that, or you can declare all the globals as NULL as I've outlined
above...

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list