Help with Error Code?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dazmanaz
Posts: 3
Joined: Wed Sep 14, 2011 3:12 pm

Help with Error Code?

Post by dazmanaz » Wed Sep 14, 2011 7:52 pm

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

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm

Re: Help with Error Code?

Post by WaltBrown » Wed Sep 14, 2011 8:13 pm

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
Walt Brown
Omnis traductor traditor

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Help with Error Code?

Post by Dixie » Wed Sep 14, 2011 8:14 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Help with Error Code?

Post by mwieder » Wed Sep 14, 2011 9:04 pm

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.

Post Reply