x


add a float and object

I'm trying to add the accelerometer value and collect the up but keep getting this error:

Operator '+' cannot be used with a left hand side of type 'float' and a right hand side of type 'object'

Do I need to cast something?

y = iPhoneInput.acceleration.z + y;
more ▼

asked May 01 '10 at 10:38 PM

rd42 gravatar image

rd42
296 30 37 46

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

What programming language are you using? You can't just do "y = something", you have to instantiate your variable first.

// C#
float y;
y += iPhoneInput.acceleration.z;

// JS
var y : float;
y += iPhoneInput.acceleration.z;

If you're accumulating your variable, you might also want to make your "y" variable a global variable inside your class.

more ▼

answered May 01 '10 at 10:42 PM

qJake gravatar image

qJake
11.6k 43 78 161

Sorry about that, I figured it was assumed that it was instantiated. I initially was using '+=' but was getting an error that I later discovered was the result of my trying to add and object and a number. Thanks for your help.

May 03 '10 at 12:18 PM rd42
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3738
x2000
x69

asked: May 01 '10 at 10:38 PM

Seen: 1225 times

Last Updated: May 03 '10 at 09:59 PM