People have mentioned that you need the global command or declaration in both 
the button script and the card script.  You can put it within each of the 
applicable handlers or, once outside of handers before any handlers that need 
it.

However, there are two other potential problems that might create some 
confusion.

1.  Keys are strings.  The result of arithmetic (and sometimes binaryDecode) 
will have to be converted to a string using numberFormat (a handler property).  
If numberFormat is (say) "0.00" then using 0+1 as the key would result in 
"1.00" being used as the key.  That is not the same as "1".  In startbb in your 
mail you are using strings as keys.  However, should you change that to a loop, 
a loop where the values for the keys are calculated, some or all would be 
numbers and numberFormat would apply before the value is used as a key.   In 
your example, the problem can occur at the other end with no script changes; if 
you have an extra space in the field "numbers" or a leading zero, you will not 
get the same element as you would without.  So, look for an extra space in 
field "numbers" and be careful of numberFormat in setting the array elements.  

2.  There is no initialization.  You are not clearing the array.  That is 
probably not a problem, but as you are tinkering you might leave extra elements 
in the array and be surprised when you look up something goofy from field 
"numbers" and actually get something.  You can programmatically clear the array 
by setting it to empty, such as at the start of startbb.  

Dar


On Jun 30, 2013, at 10:11 AM, David Milne wrote:

> 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
> 
> 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.
> 
> Regards
> 
> David Milne
> _______________________________________________
> use-livecode mailing list
> [email protected]
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to