Fuck Discord. Hi I'm Brook,

The Partridge Family were neither partridges nor a family. Discuss.
Tsplinter
Posts: 20
Joined: April 10th, 2018, 5:11 pm

Re: Fuck Discord. Hi I'm Brook,

Post by Tsplinter » June 1st, 2018, 4:23 am

I'll try imgur.

And... idk. I have a an account and I have to remember my log in. The image is attached if you want to look at 2 posts back. In the meantime, I'll work on the embed link.
It's most likely nothing a nap wouldn't fix

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Fuck Discord. Hi I'm Brook,

Post by albinopapa » June 1st, 2018, 4:52 am

Yeah, I saw the image, and I didn't comment on it because between my previous post on the original subject and chili's hint about the const keyword, I figured there was nothing more to say on the matter.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Tsplinter
Posts: 20
Joined: April 10th, 2018, 5:11 pm

Re: Fuck Discord. Hi I'm Brook,

Post by Tsplinter » June 1st, 2018, 5:27 pm

https://msdn.microsoft.com/en-us/library/07x6b05d.aspx
Says

"When modifying a data declaration, the const keyword specifies that the object or variable is not modifiable.

Syntax

const declaration ;
member-function const ;

const values
The const keyword specifies that a variable's value is constant and tells the compiler to prevent the programmer from modifying it.

// constant_values1.cpp
int main() {
const int i = 5;
i = 10; // C3892
i++; // C2105
}

In C++, you can use the const keyword instead of the #define preprocessor directive to define constant values. Values defined with const are subject to type checking, and can be used in place of constant expressions. In C++, you can specify the size of an array with a const variable as follows:

// constant_values2.cpp
// compile with: /c
const int maxarray = 255;
char store_char[maxarray]; // allowed in C++; not allowed in C

In C, constant values default to external linkage, so they can appear only in source files. In C++, constant values default to internal linkage, which allows them to appear in header files.

The const keyword can also be used in pointer declarations.

// constant_values3.cpp
int main() {
char *mybuf = 0, *yourbuf;
char *const aptr = mybuf;
*aptr = 'a'; // OK
aptr = yourbuf; // C3892
}

A pointer to a variable declared as const can be assigned only to a pointer that is also declared as const.

// constant_values4.cpp
#include <stdio.h>
int main() {
const char *mybuf = "test";
char *yourbuf = "test2";
printf_s("%s\n", mybuf);

const char *bptr = mybuf; // Pointer to constant data
printf_s("%s\n", bptr);

// *bptr = 'a'; // Error
}

You can use pointers to constant data as function parameters to prevent the function from modifying a parameter passed through a pointer.

For objects that are declared as const, you can only call constant member functions. This ensures that the constant object is never modified.

birthday.getMonth(); // Okay
birthday.setMonth( 4 ); // Error

You can call either constant or nonconstant member functions for a nonconstant object. You can also overload a member function using the const keyword; this allows a different version of the function to be called for constant and nonconstant objects.

You cannot declare constructors or destructors with the const keyword.

const member functions
Declaring a member function with the const keyword specifies that the function is a "read-only" function that does not modify the object for which it is called. A constant member function cannot modify any non-static data members or call any member functions that aren't constant.To declare a constant member function, place the const keyword after the closing parenthesis of the argument list. The const keyword is required in both the declaration and the definition.

// constant_member_function.cpp
class Date
{
public:
Date( int mn, int dy, int yr );
int getMonth() const; // A read-only function
void setMonth( int mn ); // A write function; can't be const
private:
int month;
};

int Date::getMonth() const
{
return month; // Doesn't modify anything
}
void Date::setMonth( int mn )
{
month = mn; // Modifies data member
}
int main()
{
Date MyDate( 7, 4, 1998 );
const Date BirthDate( 1, 18, 1953 );
MyDate.setMonth( 4 ); // Okay
BirthDate.getMonth(); // Okay
BirthDate.setMonth( 4 ); // C2662 Error
}

C and C++ const Differences
When you declare a variable as const in a C source code file, you do so as:

const int i = 2;

You can then use this variable in another module as follows:

extern const int i;

But to get the same behavior in C++, you must declare your const variable as:

extern const int i = 2;

If you wish to declare an extern variable in a C++ source code file for use in a C source code file, use:

extern "C" const int x=10;

to prevent name mangling by the C++ compiler.

Remarks
When following a member function's parameter list, the const keyword specifies that the function does not modify the object for which it is invoked."
It's most likely nothing a nap wouldn't fix

Tsplinter
Posts: 20
Joined: April 10th, 2018, 5:11 pm

Re: Fuck Discord. Hi I'm Brook,

Post by Tsplinter » June 1st, 2018, 5:33 pm

I guess my crayons aren't real sharp in trying to grasp why the function with lines of Putpixel code must come after every function trying to declare them and how that relates to const.

I skip over it for now and hopefully pick it up some when and where else.
It's most likely nothing a nap wouldn't fix

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Fuck Discord. Hi I'm Brook,

Post by chili » June 1st, 2018, 5:42 pm

Tsplinter wrote:why the function with lines of Putpixel code must come after every function trying to declare them
I still don't get what you mean here bro. Maybe if you could elaborate with examples of what you mean. The 'function with lines of putpixel code' does not have to come after any function. And what do you mean by 'every function trying to declare them'? What are 'them'?
Chili

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Fuck Discord. Hi I'm Brook,

Post by albinopapa » June 1st, 2018, 6:47 pm

In my original reply, I stated that the processor executes lines of code in order they appear for the most part. So you set or update a variable before you draw it's representation in order to get the newest location drawn.

if x is set to 400 then you call PutPixel, your pixels will be drawn at 400.
If you add 10 to x after you call PutPixel, how is it suppose to draw at 410 if it's already been drawn at 400?
This is why you have to set to 400, add or subtract 10 depending on the direction key being pressed, then draw. If nothing was pressed, pixels will be drawn at the original 400. If UP is pressed, you will get 400 - 10 = 390, then you draw starting at 390.

The issue with the const that chili was referring to was in your screen shot, you have const int x = 400; This means that you will not be able to update x to 390 or 410 because x is constant. Look at the image, there is a red squggle underlining the x inside the if statement. He was referring to this probably thinking this was your issue.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Fuck Discord. Hi I'm Brook,

Post by albinopapa » June 1st, 2018, 7:10 pm

Think about this logically, take it step by step.

You have five dollars.
You go to the store and spend 3 dollars.
You mom asks how much money do you have left

Your answer before you go to the store would be 5 dollars.
Your answer after you go to the store would be 2 dollars.

Same goes for drawing.
Your reticle starts at ( 400, 300 )
You add 10 in the X direction ( 410, 300 )
You draw your reticle

If you draw before updating your reticle will be drawn at (400,300)
If you draw after updating your reticle will be drawn at (410,300)

Doing gfx.PutPixel( x + 0, y -5, 255, bg, bg ); isn't a declaration, it's a function call.
A function declaration is what you see in the files ending in .h ( a.k.a header files ). Similar to order of execution, the compiler needs to know about the function's signature ( it's declaration ) before it can be used. This is why we have the #include "Graphics.h" stuff at the top of either the header files like Game.h or the source ( .cpp ) files, so the compiler can look back at the included files for the declaration and determine if the variables you pass in are valid or not.

The stuff in the source file ( sometimes called the translation unit and usually ending in .c for C and .cpp for C++) is where you keep the definitions of the functions you've declared in the header files.

In Game.h, you have your Game class with a declared function with the signature:
void UpdateModel();

It's definition is similar, but scoped to the Game class using the name of the class followed by the scope resolution operator ::

Code: Select all

void Game::UpdateModel()
{
    // Actual code goes here
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Tsplinter
Posts: 20
Joined: April 10th, 2018, 5:11 pm

Re: Fuck Discord. Hi I'm Brook,

Post by Tsplinter » June 1st, 2018, 9:16 pm

albinopapa wrote:In my original reply, I stated that the processor executes lines of code in order they appear for the most part. So you set or update a variable before you draw it's representation in order to get the newest location drawn.

if x is set to 400 then you call PutPixel, your pixels will be drawn at 400.
If you add 10 to x after you call PutPixel, how is it suppose to draw at 410 if it's already been drawn at 400?
This is why you have to set to 400, add or subtract 10 depending on the direction key being pressed, then draw. If nothing was pressed, pixels will be drawn at the original 400. If UP is pressed, you will get 400 - 10 = 390, then you draw starting at 390.

The issue with the const that chili was referring to was in your screen shot, you have const int x = 400; This means that you will not be able to update x to 390 or 410 because x is constant. Look at the image, there is a red squggle underlining the x inside the if statement. He was referring to this probably thinking this was your issue.
I think this is the explanation I needed. I'll sort out my Github account and provide 2 different repos if you want. I wish I could have been more clearer on what I'm struggling with. Sorry about that.
It's most likely nothing a nap wouldn't fix

Tsplinter
Posts: 20
Joined: April 10th, 2018, 5:11 pm

Re: Fuck Discord. Hi I'm Brook,

Post by Tsplinter » June 1st, 2018, 11:19 pm

"...you set or update a variable before you draw it's representation in order to get the newest location drawn.

if x is set to 400 then you call PutPixel, your pixels will be drawn at 400.
If you add 10 to x after you call PutPixel, how is it suppose to draw at 410 if it's already been drawn at 400?
This is why you have to set to 400, add or subtract 10 depending on the direction key being pressed, then draw..."

It just seemed to me that before you called any "if statements" saying what to do with the putpixels you'd want to call the putpixels first. I guess I was initially thinking I'd get a compiler error if I did it the other way (the right way). Thanks for your patience in helping me understand my malfunction. If my Programmer talk is all wrong feel free to tell me.
It's most likely nothing a nap wouldn't fix

Post Reply