Why does this program not work?

Mike Kerner MikeKerner at roadrunner.com
Sun Jun 30 12:48:31 EDT 2013


David,
One exception to what Klaus said - you can declare global or local
variables and have them be visible to all handlers within a particular
script - in other words, all handlers within a particular script window, no
matter how many handlers are in that script window.

So if in a button's script you have



global someGlobal


on mouseUp
....
end mouseUp



on something
...
end something


on somethingElse
...
end somethingElse


the "someGlobal" variable will have scope (be visible with its shared
value) within all those handlers.  Then if in the stack or card script or
some other button you declare the same global, it will also be be scoped in
those handlers, with the shared value.
If you want to only have a variable available within a particular script,
i.e. window, but you want all handlers in that script to have access to it,
then declare it as local instead of global.  Think of locals as being more
like object properties - outside of that script window the value is not
shared.  Unlike an object property, you cannot retrieve or set the value of
a local outside of the script.



On Sun, Jun 30, 2013 at 12:18 PM, Klaus major-k <klaus at major-k.de> wrote:

> HI David,
> Am 30.06.2013 um 18:11 schrieb David Milne <dmilne at ihug.co.nz>:
>
> > Hello all,
> >
> > I would be very grateful if some one can explain to me why the following
> > program does not work. It is a cut down demonstration program designed to
> > show the fault.
> >
> > I made the following in the latest community version of LiveCode.
> >
> > I made a card with  a button "button", a field "numbers" and a field
> > "results"
>
> ################################
>
> > The card script was:
> >
> > global bb, aa
> >
> > on startbb
> >  put "A" into bb[0]
> >  put "B" into bb[1]
> >  put "C" into bb[2]
> > end startbb
>
> #################################
>
> > Button "Button" has the script
>
> This should work ;-)
>
> global bb, aa
>
> > on mouseUp
> >  startbb
> >  get the field "numbers"
> >  put it into aa
> >  put bb[aa] into field "results"
> > end mouseUp
> >
> > The program does not work. There were no compiling error messages.
> >
> > Could some one please explain what is wrong. I tried a variety of other
> > things, but I want to keep this email short.
> >
> > I wanted to program some logic tables, but in LiveCode, I just fail. I
> just
> > reach a blank wall.  The above little snippet program demonstrates what I
> > can not do. It is not much fun when something that one feels should be
> > obvious, simply does not work.
> >
> > Any help would be much appreciated.
>
> You need to declare globals in every scrupt you are using them!
>
> > Regards
> >
> > David Milne
>
> Best
>
> Klaus
> --
> Klaus Major
> http://www.major-k.de
> http://www.major-k.de/bass
> klaus at major-k.de
>
>
> _______________________________________________
> 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
>



-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."



More information about the use-livecode mailing list