Tutorial #5 Questions

The Partridge Family were neither partridges nor a family. Discuss.
Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Tutorial #5 Questions

Post by Ziltwix » January 28th, 2017, 2:16 pm

Hey guys! Thank you all first for helping me with this question. Now, I have received an error when I try to move the reticle to the edge of the screen after I have called this function:

Code: Select all


IsBoxMode = false;
	if (x < 200 || x > 300)
	{
		IsBoxMode = true;
	}
My reticle is able change when it leaves said part of the frame, but when I go either to the left edge of the screen it says "Expression: x >= 0"

The same goes for moving to the bottom of the screen. It says Expression: y < int (Graphics::ScreenHeight)

The same goes with this code:

Code: Select all

IsBoxMode = false;
	if (x < 200)
	{
		IsBoxMode = true;	
	}

	if (x > 300)
	{
		IsBoxMode = true;
	
	}
Any suggestions on how to approach this error?

Thank you everyone!

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Tutorial #5 Questions

Post by MrGodin » January 28th, 2017, 4:33 pm

Expression: x >= 0 is most likely an assertion raised in the put pixel function stating that an x value of one or more of the pixels in the retical is being draw out of bound ie: less than 0. same for y except it's out of bounds by going over ScreenHeight.
assert( x >= 0) means all is well so long as x >= 0. assert(y < int (Graphics::ScreenHeight)) means all is well so long as y is < int (Graphics::ScreenHeight).
You cannot draw outside the bounds of 0,0,screenWidth-1,screenHeight -1.
Curiosity killed the cat, satisfaction brought him back

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Tutorial #5 Questions

Post by Ziltwix » January 30th, 2017, 2:59 pm

MrGodin, so is that a normal thing?
What if I wanted to move the reticle to those edges to ensure my code functions properly?
What is the best course of action or the best code to prevent those errors from popping up?

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Tutorial #5 Questions

Post by MrGodin » January 30th, 2017, 3:42 pm

Well i just watched Tutorial #5 again, and chili explains exactly what to do ;). You want to test if you are near the edge.
assuming the retical main x position is the center, and the outer pixels are 5 from the center or a total width of 10

Code: Select all

if( x  - 5 <=0 ) 
{
  x = 5;// set if less than or equal to 0.
}
if( x + 5 > 799)
{
 x = 799 - 5;
}
if (y - 5 < 5)
{
 y = 5;
}
if ( y +  5 >= 599)
{
 y = 599 - 5;
}
It's all there in the video
Curiosity killed the cat, satisfaction brought him back

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Tutorial #5 Questions

Post by Ziltwix » January 30th, 2017, 4:00 pm

I see that you did it differently! I just called the gfx.ScreenWidth or gfx.ScreenHeight function.

The code I have here is different.

Code: Select all

if (x + 5 >= gfx.ScreenWidth)
	{
		x = gfx.ScreenWidth - 6;
		vx = 0;
	}
	if (x - 5 <= 0)
	{
		x = 5;
		vx = 0;
	}
	if (y + 5 >= gfx.ScreenHeight)
	{
		y = gfx.ScreenHeight - 6;
		vy = 0;
	}
	if (y - 5 <= 0)      //This here is the problem because I tested running the reticle along the
	{                        //Bottom edge but the assertion failed around x 200ish pixels.
		y = 5;
		vy = 0;
	}
In the end, I'm just trying to get the reticle hit all edges, especially when I have the code I showed you all when I first posted this thread.

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Tutorial #5 Questions

Post by MrGodin » January 30th, 2017, 7:45 pm

If you can upload your project, I will look at it because i cannot see what the issues is in this code here :) You can find how to do that here
http://forum.planetchili.net/viewtopic.php?f=3&t=2
Curiosity killed the cat, satisfaction brought him back

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Tutorial #5 Questions

Post by Ziltwix » February 2nd, 2017, 10:43 pm

Hey MrGodin! Sorry for the late reply, my friend.

I hope this is the correct way to do it. Let me know if I am missing anything important! Thank you again for the help!

Look for this tagline:

//The Code Below Changes The Shape Of The Reticle When It Enters These Parameters.
Attachments
chili_clean.zip
(2.5 KiB) Downloaded 120 times

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Tutorial #5 Questions

Post by MrGodin » February 2nd, 2017, 11:49 pm

From looking at your Game.cpp file you have this
a part of you edge correction

Code: Select all

if (x - 5 <= 0)
	{
		x = 5;
		vx = 0;
	}
and this for your box mode

Code: Select all

if (x < 200 || x > 300)
		{
			IsBoxMode = true;
		}
The issue seems to be when you go into box mode ( x < 200 ) for example, you draw your box, but .....
when you are checking edges you haven't taken into account that the box is larger then the reticle.
Looking at your putpixel calls you have this

Code: Select all

gfx.PutPixel(-11 + x, 7 + y, rg,rg,255);
Can you see the issue, or what i believe is the issue,? lets go back to the edge correction where you have this
if (x - 5 < 0) .. where the putpixel above has -11 + x (which subtracts as i'm sure you know)which puts you out of bounds. So you need to make your box the same size (width and height) as your reticle, or do another correction from the edges for the box.
Hope it makes sense, i'm not the best at explaining :)
Peace
Curiosity killed the cat, satisfaction brought him back

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Tutorial #5 Questions

Post by Ziltwix » February 3rd, 2017, 5:12 pm

Thank you for the help, MrGodin! What you believe when you think that you did not give me proper explanation, you in fact did. So I will mess about this the code and reply when everything is in order.

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Tutorial #5 Questions

Post by MrGodin » February 3rd, 2017, 5:21 pm

Ziltwix wrote:Thank you for the help, MrGodin! What you believe when you think that you did not give me proper explanation, you in fact did. So I will mess about this the code and reply when everything is in order.
Good luck :)
Curiosity killed the cat, satisfaction brought him back

Post Reply