• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KevinWalters

Basic C++ Help Maybe?

7 posts in this topic

Okay I have a weird issue going on here that I can't seem to figure out. I must let you all know that I'm running Xubuntu 13.04 using gedit and g++ through terminal. Yeah this is how I wanted to start learning C++ and I was told this would be the best way. Here is my code.

// Game Stats
// Demonstrates declaring and initializing variables

#include <iostream>
using namespace std;

int main()
{
	int score;
	double distance;
	char playAgain;
	bool shieldsUp;

	short lives, aliensKilled;

	score = 0;
	distance = 1200.76;
	playAgain = "y";
	shieldsUp = true;
	lives = 3;
	aliensKilled = 10;

	double engineTemp = 6572.89;

	cout << "\nscore: " << score << endl;
	cout << "distance: " << distance << endl;
	cout << "playAgain: " << playAgain << endl;
	//skipping shieldsUp since you don’t generally print Boolean values
	cout << "lives: " << lives << endl;
	cout << "aliensKilled: "<< aliensKilled << endl;
	cout << "engineTemp: " << engineTemp << endl;

	int fuel;
	cout << "\nHow much fuel? ";
	cin >> fuel;
	cout << "fuel: " << fuel << endl;

	typedef unsigned short int ushort;
	ushort bonus = 10;
	cout << "\nbonus: " << bonus << endl;

	return 0;
}

Now when I try to compile in terminal this is the error I'm getting.

************~/Desktop/dev/src$ g++ gamestats01.cpp -o gamestats01
gamestats01.cpp: In function ‘int main()’:
gamestats01.cpp:18:14: error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]
************~/Desktop/dev/src$ 

Can someone give me some insight on this? Also I have never programmed a day in my life. Is this okay for me to be using Linux and Terminal for starting? I hate Windows and would prefer not to touch it if I don't have to.

0

Share this post


Link to post
Share on other sites

 

Double quotes are used to define strings, single quotes are used to define a character. You want:

playAgain = 'y';

 

Sir as basic as that is you are awesome! Compiled perfectly fine thank you very much!

0

Share this post


Link to post
Share on other sites

Just some tips:

 

Please teach your self to move "using namespace <namespace_name>;" into a function call or wrapped in another namespace, preferably the first option. This is because you have just polluted the global namespace with all the names of std, which is bad and can in cases lead to compiler errors that look really strange.

 

Slightly better way to write the initial declaration and initialisation of the variables is like this

    int score = 0;
    double distance = 1200.76;
    char playAgain = 'y';
    bool shieldsUp = true;

    short lives = 3; //Don't define multiple variables on the same line this can create issues for you when declaring references and pointers on one line
    short aliensKilled = 10;

The reason for this is that you will not forget to initialise a variable, C++ doesn't automatically do this for you, so untill you actually assign a value to a variable it has an undefined value(usually whatever the memory is at the time the variable is declared and given a memory area to use).

 

Thank you for the information. I'm actually reading the book Beginning C++ Through Game Programming Third Edition and I think it's going to show me just that. It takes you through the basics first and then shows you how to write the same program in a different format which I like so I'm not confused when I see it one way or the other like yours. You guys are awesome I didn't know this community was so active and helpful!

0

Share this post


Link to post
Share on other sites

You also have the option of changing the datatype to string. Include the string header.
 
//Include the string header
#include <string>
 
Then change the datatype to string. 
 
string playAgain;
 
If that was the only issue with the original code, then it should compile fine.

0

Share this post


Link to post
Share on other sites

So after taking some advice I cleaned up the code a bit. Tell me what you think. Also is there like a IRC or Mumble server which has a bunch of game programmers that we can ask advice or hangout with? That would be amazing if someone could share me some info on that.

// Game Stats
// Demonstrates declaring and initializing variables

#include <iostream>
using namespace std;

int main()
{
	// Establishing variables and values
	int score = 72;
	double distance = 1200.76;
	char playAgain = 'y';
	bool shieldsUp = true;
	short lives = 3;
	short aliensKilled = 10;
	double engineTemp = 6572.89;
	int fuel;

	// Printing information to screen
	cout << "\nScore: " << score << endl;
	cout << "Distance: " << distance << endl;
	cout << "Play Again?: " << playAgain << endl;
	cout << "Shields Up?: " << shieldsUp << endl;
	cout << "Lives: " << lives << endl;
	cout << "Aliens Killed: "<< aliensKilled << endl;
	cout << "Engine Temp: " << engineTemp << endl;
	
	// Printing information and receiving information
	cout << "\nHow much fuel? ";
	cin >> fuel;
	cout << "Fuel: " << fuel << endl;

	// Defining different types into user type
	typedef unsigned short int ushort;
	ushort bonus = 10;
	cout << "\nBonus: " << bonus << endl;

	// Ending program
	return 0;
}
0

Share this post


Link to post
Share on other sites

you should avoid "using namespace std;" - this tells the compiler "look in the namespace std for all types" and can be a problem when you start using other namespaces.

 

For example: if you have a namespace "gameStuff" and there's a type called "cout" in there the compiler will be looking in the wrong namespace.

Because 'std' contains a 'cout' type the compiler won't know that something is wrong and the program will compile, then you get to look for the bug

(it uses std::cout when it should have been gameStuff::cout)

 

You can either:

- put using namespace std in the main function (that's what nightcreature was talking about). This will tell the compiler "using this namespace but only for this function")

- be more specific with your using statements, that is:

using std::cout;
using std::cin;
using std::stringstream;

instead of the much more broad "using namespace std".

 

 

If you want to chat with us you can! After you've logged in there will be a link to the chat page. You'll find it at the top of the page, below the search box. You can also login with an IRC client but I don't recall the address at the moment.

Edited by molehill mountaineer
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0