Checking my Progress in Game Programming

Started by
18 comments, last by Servant of the Lord 11 years, 7 months ago
Thanks for the response smile.png

I had a feeling a month of c++ wouldn't get it in place so it's nice to get some feedback. At least I know I need to practice some more and read a bit more also.
I did know that if you cout a pointer you'll get the memory address and not the variable value itself hence them always being integers, if that is what you meant.

Still much appreciate the response.

Regarding the member variable.

I think I kinda switched around local and member didn't I?

Local being class visible and member being function specific.

Again much appreciated! biggrin.png
Advertisement

Your response to pointers is wrong in concept.
Your response to members is wrong entirely.

As for pointers, you gave basically a textbook definition of how they are used, but not really what they are. They are nothing but integers whose values can be interpreted as an address. Their sizes change between platforms but to keep things simple we should assume Windows x86 (32-bit pointers).
0x00000100 can’t be a pointer but 0x00400000 is. It is simply a value that points to valid memory. Though some values that are meant to be pointers could point to invalid memory if your program has errors.


Members are “attributes” of classes. You posted an example in which a function was declared inside another function. This is entirely illegal.
For this, you need to redo some of your learning.


L. Spiro


Looks like someone was before me smile.png But I don't mind at all, you've explained it 10x better than I would've done!
I was going to say: "Pointers are addresses. Nothing more nothing less. They only "point to" an object which is allocated on the heap(or on the stack, depending where/how you have allocated your object. But most likely it will be on the heap).
But indeed you need to be careful using pointers.


Assume this code:

int main()
{
Object* pObject1 = new Object();
Object* pObject2 = pObject1;

delete pObject1;

pObject2->ShootBlast();
}

If you don't know what this code will do, too bad I won't tell it! biggrin.png
Write it in C++ and use break points to look what each step will do.
if you like this kind of thinking-work of this code, send a PM because I have tons of these thinking-codes. smile.png

LarcDC, you bad bad boy! tongue.png My question wasn't meant as a challenge. biggrin.png


~EngineProgrammer
Engine Programmer,

My goal is to learn how to program, with the ultimate goal of learning how to program games. As you can see these are the very, VERY first games I have ever created and you can probly tell this too, I am practically teaching myself with the help of a book or two. Do any of you guys know the TI-84 Plus Silver Edition Graphing Calculator? I first learned how to program on that when I was getting tired of doing the Quadratic Formula over and over again. I then got interested in writing code and then into coding games and then into trying to program on the computer. I then got to the point where the books were going to slow, so I went ahead and started to implement what I had learned so far into these "Games". Putting up the source code for these games was a very good decision by me because of all of these tips I have recieved. I just wanted to say thanks so much, and if you guys have anything else you want me to know or clean up, then please put it all out here:)
Thanks again!!!,
Saint Squireen

~Saint Squireen
Well, if you follow the pdf I've linked to you in my first comment I'm sure you will be a much better programmer soon!

I still remember my first piece of code. I only knew what data members, bitmaps and methods were.
I wrote 1000lines of code for a simple sprite of Warcraft2-Tidens of darkness that could move around the map and plays a random sound when you select it.
And 4 months later I looked again to that code and I really wanted to laugh at myself of being so bad. But when I compared with the progress I've made I was really glad.
The pdf shows you all basics of C++ and you can learn it in 1 month.(but go over it slowly, so take 2 months)

Also I remember I've followed some tutorials on websites to program in C++:
Console Applications: http://xoax.net/cpp/...nsole/index.php
Win32: http://xoax.net/cpp/...win32/index.php

And yes I sure want to tell you something more so you won't make the mistake I did. Listen and follow the advice of good programmers.
I learned Winsock(networking stuff) and I've been told to learn Raknet(better networking stuff) but didn't listened. And on the finals I didn't have a networking system in my game(wasn't really needed but I was going for the extra points). All because I 'was' stubborn. smile.png
I'm not saying you need to listen to me, I'm far away of being a good programmer. L. spiro is a great programmer, I've looked at some of his comments and I noticed allot of details he can tell on a single topic.


~EngineProgrammer
Several tips and one criticism:
1) Don't be afraid to use whitespace. It makes the code easier to read. Easier to read is better than not easy to read.
2) Don't cram multiple things onto one line 'just because'.

For example, this:
int topLeft=0,topCenter=0,topRight=0,middleLeft=0,middleCenter=0,middleRight=0,bottomLeft=0,bottomCenter=0,bottomRight=0,turn=0,restart=1,playerMove=0,compMove=0,playerMoveAccept=0,compMoveAccept=0,win=0,fourCorners=0,care=0,chance=0,difficulty=0,placement=0;

Should be:
int topLeft = 0, topCenter = 0, topRight = 0;
int middleLeft = 0, middleCenter = 0, middleRight = 0;
int bottomLeft = 0, bottomCenter = 0, bottomRight = 0;
int turn = 0;
int restart = 1; //What is restart? It either isn't named very descriptively, or else should be a boolean.
int playerMove = 0, compMove = 0; //Maybe these should be bools also?
int playerMoveAccept = 0, compMoveAccept = 0;
int win = 0; //Bool?
int fourCorners=0;
int care = 0; //Needs more discriptive name, and also should be a bool.
int chance = 0, difficulty = 0, placement = 0;


Use constants or enums wherever applicable. Avoid as many magic numbers as you can.

Declare any variables as close to the first use as reasonable. Definitely declare them in the proper scope. Don't make them all globals. Some globals are okay though.

Learn if else() and else and use them where appropriate.

[hr]

You're doing good, so keep at it! All of the above is just tips to improve and get better. There's still a ways to go, but you're just starting out so that's to be expected. smile.png

Now for the one real criticism:

What in the world is this? angry.png
if(middleCenter==1 and topLeft==0 and topRight==0 and bottomLeft==0 and bottomRight==0)
{
//...
}


'and' is not a C++ keyword. If you have a macro named 'and' that is defined as '&&', get rid of it! dry.png

[size=2](*tongue-in-cheek anger*)

'and' is not a C++ keyword. If you have a macro named 'and' that is defined as '&&', get rid of it! dry.png


Actually it is and it is the same as &&. However, absolutely nobody uses it to the point where I didn't even know about it after almost 10 years of C++. Maybe it's because && is easier to type or simply because it sticks out a lot better than 'and'. Basically, use && and || instead of 'and' and 'or', unless you are extremely paranoid of accidentally using & and | instead.
f@dzhttp://festini.device-zero.de
Oh wow, I never knew that. I've never seen them used in C++, and most C++ operator lists don't even mention them (but it does here).

Because of their very uncommon use (in C++), I would still recommend getting rid of them and use the more commonly recognized symbols.
I've seen "and" sparingly used in some old PHP code, but I also have never seen it being used in any recent examples. Whoever or whatever sources you've used to learn the C++ language must have some interesting but outdated approaches.

2) Don't cram multiple things onto one line 'just because'.[/quote]

Following this advice is not only to make code easier to read, but also to make it far easier to debug.

If you get a syntax error in runtime, or logical error causing a crash and the debugger points to line XX being the problem line, it's gonna be harder to know exactly what in that line made it crash if you had multiple statements going on.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

“and” and “or” are very rare and I have never seem them in practice, but at least they are documented.
Here is a snippet of code that may look entirely alien to most of you.


int iBlah<:100:>;
if ( bBleegers and bBloopers )
for ( int i = sizeof( iBlah ) / sizeof( iBlah<:0:> ); i--; ) <% iBlah<:i:> = i; %>


I wrote this on paper for my coworkers today and asked, “What language is this?”.
All of them are very experienced and none of them were able to answer correctly.

It’s plain C/C++. Actually “and” is not a C keyword, but the rest of it will compile in any C compiler (assuming you have declared bBleegers and bBloopers).
Try it for yourself.

C/C++:
<% = {
%> = }
<: = [
:> = ]

C++ Only:
and = &&
or = ||


These tokens were created because 20 years ago not all keyboards had &, |, {, }, [, and ] characters. So these are all exact drop-in replacements.


Again, I have never seen any of these in actual use and there seems not to be any documentation of it anywhere.
The only reason I know about them is because I wrote a C compiler a long time ago.
The lexer grammar for ANSI C can be found here:
http://www.lysator.l...-grammar-l.html


All that being said, I have to honestly question how the original poster knew about “and” and especially why he or she is actually using it.
It does not appear in tutorials or books. How could a beginner possibly not know about and use &&? Any learning resource you ever find will be using only &&, so I have to ask, where on earth did you learn C++? Even if you come from a scripting background you would have had to look at some tutorial or learning source on C++ somewhere, and there is no chance it would have been using &&…


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I'm familiar with ternary (though I don't have them memorized).

As to where he learned it, I don't think it's that hard to accidentally learn if you're coming from a different language that uses AND and OR.

For example:

I've seen "and" sparingly used in some old PHP code, but I also have never seen it being used in any recent examples.


When I read that I smiled to myself half-embarrassed, because over the past 30 days I've had to learn PHP for getting my game's website up and running... and I was using 'and' and 'or' the entire time. Only once CC Ricers indicated it was outdated and unused, did I realize that PHP even had && and ||.

'course now I''ve switched to && and || in PHP, since that's what I'm more familiar with from C++ anyway. Plus I like that && and || are so tall and distinguishable from other letters, that they act as visual separators between variable names. (run and gun) vs (run && gun)

This topic is closed to new replies.

Advertisement