You have discovered what's known as a "local" variable.  The variable is 
local to the handler (in this case, 'mouseUp') and doesn't persist past the 
end of the handler.  It goes what is known as "out of scope" and no longer 
exists.  The next time in, a new one is created, and initialized to VOID (a 
null value).

If you declare the variable as 'global', it will persist outside of the 
handler, meaning that it will always be "in scope" (as long as you specify 
that you're using the 'global' version.  That will allow you to increment 
it each time through.

You will also want to initialize it.

The minimum solution is:

  on mouseUp
    global gIncre

    gIncre =gIncre + 2
    put gIncre
  end

This will add 2 to the variable each time.  Saying it's in the global 
namespace means that any references to gIncre in that scope (in this case, 
the handler) will refer to the global version.

NULL translates to 0, and you can get away with it, but a better solution 
(more correct) would be:

  on mouseUp
    global gIncre

    if (voidP(gIncre)) then
       gIncre =0
    end if

    gIncre =gIncre + 2
    put gIncre
  end


So, the first time through it will be void and you will initialize it to 
0.  Effectively the same, but a bit more correct this way.

- Tab


At 10:23 PM 2/25/02 -0500, two two two wrote:


>I have a very very basic lingo question.
>
>--------------
>
>on mouseUp
>   gIncre =  gIncre + 2
>   put gIncre
>end
>
>
>--------------
>
>I'm trying create a lingo script where every time I click on text, the
>number increment.  Here I'm just trying to "put" the updated number in the
>message window.
>
>
>Any ideas where my problems are?
>_____________________________________
>
>Garman Herigstad
>912-897-1108
>[EMAIL PROTECTED]

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to