Page 1 of 1

Tutorial 20 pt.1:Fart annoyed curious on bool and void

Posted: June 19th, 2019, 6:09 am
by dawg_duggart
Hey man. So I did some experimentation on Fart Annoyed. I made the DoWallCollision into void function instead of bool. Everything is cool but when the ball hits the wall it doesnt rebound, it will display assertion failed. I know the difference between the two functions (bool returns bool values and void returns nothing) but is there something more to them that I miss.

Code: Select all

void Ball::DoWallCollision(const RectF & wall)
{
	RectF ballrect = GetRect();
	if (ballrect.left < wall.left)
	{
		pos.x += wall.left-ballrect.left;
		vel.x = -vel.x;
	}
	else if (ballrect.right > wall.right)
	{
		pos.x -= wall.right - ballrect.right;
		vel.x = -vel.x;
	}
	if (ballrect.top<wall.top)
	{
		pos.y += wall.top - ballrect.top;
		vel.y = -vel.y;
	}
	else if (ballrect.bottom > wall.bottom)
	{
		pos.y -= wall.bottom - ballrect.bottom;
		vel.y = -vel.y;
	}
}

Re: Tutorial 20 pt.1:Fart annoyed curious on bool and void

Posted: June 19th, 2019, 4:55 pm
by albinopapa
What is the message for the assertion or what condition causes the assertion?

Functions that have a return type other than void such as bool should return a value ( true or false in this case ) that you can assign to a variable or use directly such as [ if( ball.DoWallCollision( wall ) ) ] and functions that have a return type of void cannot return a value and must be called on their own. You cannot assign void to variable nor can you create a void type variable.

Re: Tutorial 20 pt.1:Fart annoyed curious on bool and void

Posted: June 20th, 2019, 2:20 pm
by dawg_duggart
My mistake man. I rewrite the code on my own from the beginning of the tutorial and everything is fine now. I think the error has something to do with the "Retarget Project" because I think I forgot to do that on my previous try. Anyway thanks man