Semantic error: Variable assignment: please help!!
HI all I have come across an error and I dont understand why I have got it.
I have 2 variables called box1 and box2 referencing objects. both objects have 2 attributes, these are colour and position.
the error occurs when I execute the following statement: [I][box2 = box1.getPosition();/I]
I get the error message: [I][Semantic error: Variable assignment: box1: Can't assign
primitive value to object type:class Box/I]
if anyone could explain this eror it would me a great deal and I will ofcourse thank the person who helps in the correct way.
Re: Semantic error: Variable assignment: please help!!
You are attempting to assign a primitive value (int, long, float, etc...) to an object (Box?), which cannot be done (values assigned to objects using equality must be of the same object class). What is the behavior you wish to have with this code, to assign the position of box2 to that of box1? Should probably be something more along these lines:
Code :
box2.setPosition( box1.getPosition() );