Page 1 of 1

Help with Error Code?

Posted: Wed Sep 14, 2011 7:52 pm
by dazmanaz
Hello,

I am working on a very simple school project using LiveCode (a recipe for cookies), however sometimes when multiplying two varibles together I encounter sometimes the error: button "Convert to Imperial": execution error at line 8 (Operators *: error in left operand), char 8"

Here is some of the code:

Code: Select all

on mouseUp
   global imperial
   
   put "Ingredients (oz):" into field "ingredients"
   
   //imperial
   put 0.0352739619 into imperial
   put s*imperial into s
   put s into field "sugar"
   put b*imperial into b
   put b into field "butter"
   put f*imperial into f
   put f into field "flour"
   //imperical measurements not needed for number of eggs
   put c*imperial into c
   put c into field "chocolate"

end mouseUp
variables s, b, f, e and c are all global variables on a different button, and their value changes depending on the number of cookies the user wishes to make. My question is relatively simple, what is going wrong? I cannot find the cause of the problem, as it seems not to occur every time I multiply varibles, only sporadically.

Thanks,

Daz

Re: Help with Error Code?

Posted: Wed Sep 14, 2011 8:13 pm
by WaltBrown
I would double check the contents of the single letter globals - it sounds like at some point (which may explain the intermittent nature) a non-number is getting into one of them, causing the left hand operand to fail. I would also try making their names a bit more unique - the one that bothers me is "f" followed on the next line with "put", "fput" being a reserved word in many other environments ("cput" less so).

Walt

Re: Help with Error Code?

Posted: Wed Sep 14, 2011 8:14 pm
by Dixie
Daz,,

Hard to say without seeing all your code... but try declaring your global variables outside of the handlers at the top of the script.

Code: Select all

global imperial

on mouseUp
   /* do your stuff here */
end mouseUp
be well

Dixie

Re: Help with Error Code?

Posted: Wed Sep 14, 2011 9:04 pm
by mwieder
Daz- note that it's not enough to declare global variables once - you have to do that everywhere you use them.

Code: Select all

global imperial
global s
Otherwise your code won't be able to access the s global variable. It'll be empty, and you end up with an error trying to multiply by an empty variable.