Variable troubles

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
lucifer1101
Posts: 42
Joined: Sun Nov 16, 2008 11:23 pm
Location: Melbourne, Australia
Contact:

Variable troubles

Post by lucifer1101 »

Im having trouble with an if command using a sprite.

Code: Select all

int mp = device->getCursorControl()->getPosition();

// if mouse < x-320
if(mp <= 0,320)
{
	driver->draw2DImage(sprite, rect<s32>(144,224,176,256),
		rect<s32>(0,0,32,32), 0, 0, true);
}

// if mouse > x-320
if(mp >= 0,320)
{
	driver->draw2DImage(sprite, rect<s32>(464,224,496,256),
		rect<s32>(0,0,32,32), 0, 0, true);
i just wanna know if im doing it right and how to do it right, but i keep getting this error

Code: Select all

main.cpp(44) : error C2440: 'initializing' : cannot convert from 'irr::core::position2d<T>' to 'int'
1>        with
1>        [
1>            T=irr::s32
1>        ]
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
i have also used the line

Code: Select all

const position2d<s32> mp = device->getCursorControl()->getPosition();
to try and initialize the variable but i get this error instead

Code: Select all

main.cpp(48) : error C2676: binary '<=' : 'const irr::core::position2d<T>' does not define this operator or a conversion to a type acceptable to the predefined operator
1>        with
1>        [
1>            T=irr::s32
1>        ]
1>c:\users\jason\desktop\irrdemos\mydemos\picturedraw1\picturedraw1\main.cpp(55) : error C2676: binary '>=' : 'const irr::core::position2d<T>' does not define this operator or a conversion to a type acceptable to the predefined operator
1>        with
1>        [
1>            T=irr::s32
1>        ]
Please help, what am i doing wrong
night_hawk
Posts: 153
Joined: Mon Mar 03, 2008 8:42 am
Location: Suceava - Romania
Contact:

Post by night_hawk »

You can not compare a position2d to a simple int. You have to use it's class members, in your case mp.X or mp.Y, which represent the coordinates.
lucifer1101
Posts: 42
Joined: Sun Nov 16, 2008 11:23 pm
Location: Melbourne, Australia
Contact:

Post by lucifer1101 »

im still kinda new to this so what needs to be changed. an am i on track with that second variable line instead of the original
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The second version is correct, you just have to change the comparisons. BTW: 0,320 is not doing what you'd expect (what would you expect anyway?!)
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Variable troubles

Post by Seven »

this line

Code: Select all

int mp = device->getCursorControl()->getPosition();
wont work because getposition() returns a structure which has two variables in it (2 int's, one called X and one called Y) and you are trying to assign that value to a single int called mp.


this code will work though, because it is assigning only one of the two ints to another int.

Code: Select all

int MouseX = device->getCursorControl()->getPosition().X;
int MouseY = device->getCursorControl()->getPosition().Y;

this will also work, because it is assigning the cursor position (a structure with two variables) to the same type of structure.

Code: Select all

position2di mp = device->getCursorControl()->getPosition(); 
and you can compre values using the structure's X,Y variables

Code: Select all

// if mouse < x-320 
if(mp.X <= 320) 
{ 
   driver->draw2DImage(sprite, rect<s32>(144,224,176,256), 
      rect<s32>(0,0,32,32), 0, 0, true); 
} 

Seven
Post Reply