Page 1 of 2

Chili, maybe god, you, can you lend me some knowledge.

Posted: August 2nd, 2016, 3:50 pm
by Denial Newell
Conundrum:(C++ Beginner Tutorial 2/homework/LazinessOrEfficiency)

I wrote expression methods for the find and replace feature; trying to be lazy moving all the pixel's x,y values at once. (Spent an hour researching because I believed a way had to exist and might be handy when/if editing repetitive string datasets. It might not be justified in this scenario, but still applicable, AND I JUST WANTED TO LEARN IT GET OFF MY CASE!)

e.g:

gfx.PutPixel(395,300,255,255,255);
gfx.PutPixel(396,300,255,255,255);

Find ((.*?),(.*?),
Replace ($1+300,$2+200,

Result:

gfx.PutPixel(395+300,300+200,255,255,255);
gfx.PutPixel(396+300,300+200,255,255,255);

Gets the job done homework complete. I could just leave it there and call it a day. But it made the strings longer, complex and requires a different expression method to alter the position again. Grave = Dug.

To locate and modify new string format

Find \((.*?)\+300,(.*?)\+200,
Replace ($1,$2,

Now, here's the question. Is there an expression method to make the calculation happen when it replaces the string to move the reticle, instead of my original method where it creates a calculation to move the reticle?

Because god knows my tiny little brain could barely comprehend how to avoid it. It would be nice if that method exists.

Otherwise, I will reset the reticle values to the top left hand side but so it keeps it's shape and use the calculation without going into negative values and remain sane.

Here is who taught me to be lazy. https://msdn.microsoft.com/en-us/library/2k3te2cs.aspx

Also I'm trash tier beginner if I confused you just delete me off the face of the internet fam. I hope I'm using the wrong names for things.

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 3rd, 2016, 12:33 am
by chili
Oh shit son, you've gone down the regex hole. I fuckin love that shit btw. I gotta catch the train to work now, answer this stuff in a bit ;)

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 3rd, 2016, 1:14 am
by chili
If I grok you correctly, you wanna do something like this this:

Code: Select all

PutPixel(301,200,255,255,255) -> PutPixel( 501,350,255,255,255 )
instead of

Code: Select all

PutPixel(301,200,255,255,255) -> PutPixel(301 + 200,200 + 150,255,255,255)
Unfortunately, regex does not deal with values like that, only simple text replacement, so this is just not possible my friend. I think your first method works completely fine though. Whenever you wanna change the position, you'd just do something like this: http://regexr.com/3du9p

Regex can be a godsend when refactoring code. Also, C++ has a RegularExpression class you can use in your actual programs to process text. I might cover VS regex in a tutorial at some point, I had meant to in the HUGS series, but then I got distracted, probably by something shiny.

Also, I like your style bro, welcome to the forums ; )

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 3rd, 2016, 4:11 am
by albinopapa
adabo tried teaching me RegEx, "I didn't have time for that". Shit is hard to understand until you get it.

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 3rd, 2016, 5:10 am
by Denial Newell
Thank you for the speedy quick fast response and new method Chili. I look forward to leeching more knowledge from you as your new series progresses my dude. And albinopapa, I believe the only reason I learnt it quickly, is because I understood how it should work it before I knew it existed.

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 4th, 2016, 5:42 pm
by PutPixel255
Chili wrote:I gotta catch the train to work now
I hope it's not a holiday :P

OK I didn't do the quote thing right, oh well.

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 4th, 2016, 9:39 pm
by albinopapa
That sounds familiar, did chili say something about catching the train to work and not realizing it was a holiday in one of his videos?

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 5th, 2016, 1:59 am
by chili
Well, I don't know for sure whether it came up in a video, but that is a thing that has happened, so it is entirely possible :p

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 5th, 2016, 5:15 am
by freebattie
Yeah you did mentioned it in the old video :) think i saw it in beginner video 6.

Re: Chili, maybe god, you, can you lend me some knowledge.

Posted: August 5th, 2016, 9:28 pm
by ScOrP!On
the way i did the solution is by making a function in the Game.h window where it says user functions
and slapped this bitch here

Code: Select all

	void cursor(int x , int y) {
     
		gfx.PutPixel(5 + x, 1 + y, 0, 0, 255);
		gfx.PutPixel(5 + x, 2 + y, 0, 0, 255);
		gfx.PutPixel(5 + x, 3 + y, 0, 0, 255);
		gfx.PutPixel(5 + x, 7 + y, 0, 0, 255);
		gfx.PutPixel(5 + x, 8 + y, 0, 0, 255);
		gfx.PutPixel(5 + x, 9 + y, 0, 0, 255);
		gfx.PutPixel(1 + x, 5 + y, 0, 0, 255);
		gfx.PutPixel(2 + x, 5 + y, 0, 0, 255);
		gfx.PutPixel(3 + x, 5 + y, 0, 0, 255);
		gfx.PutPixel(7 + x, 5 + y, 0, 0, 255);
		gfx.PutPixel(8 + x, 5 + y, 0, 0, 255);
		gfx.PutPixel(9 + x, 5 + y, 0, 0, 255);
	
	
	}
this will place the reticule in the top left corner , then u slap this function call in the Game.cpp window , under compose frame .

Code: Select all

Game::cursor(0,0);
instead of "0" , u can change the number (cant be negative) so that u can move the reticule all over the place , "cursor" is the name i gave it , u can call it whatever u want .

now if i can get the kbd.Is.Pressed bullshit to work !! (chili where u at O.o) , i would make shit happen .