Detect if game is build in debug or release mode?

The Partridge Family were neither partridges nor a family. Discuss.
EdadTace
Posts: 32
Joined: April 22nd, 2012, 10:28 am

Detect if game is build in debug or release mode?

Post by EdadTace » June 16th, 2012, 7:14 pm

hi

have been wondering if it was possible to detect in ur program whether or not you build your code in debug or release mode? so say if it was in debug mode it would allow for to turn things like godmode on and off, but when it build in release that wouldn't be possible?

I suppose i could just have a variable called debug or something that i could set to true while testing and false when for when building for release, but I'd love if it could be done automatic somehow

kratrs
Posts: 8
Joined: May 22nd, 2012, 2:46 am
Location: California

Re: Detect if game is build in debug or release mode?

Post by kratrs » June 16th, 2012, 7:26 pm

I'm pretty sure debug mode only works in your IDE. The actual .exe that you get and would send to other people would be the release mode, I think.

If you wanted there to be some way that only you could turn things like godmode on or off then maybe you would want to use a if statement at the beginning of the program to check if you're "admin" or something or have the program prompt you for a password?

I'm not sure if this is the best solution because I'm just a beginner myself, but yeah.
Image

EdadTace
Posts: 32
Joined: April 22nd, 2012, 10:28 am

Re: Detect if game is build in debug or release mode?

Post by EdadTace » June 16th, 2012, 7:32 pm

If what I've understood is right, then debug buid mode inserts some extra lines of code into ur program in order to give u error messages and stuff, so i teori it should be possible, but I don't know how.

I could also imagine that it would be different from compiler to compiler, but again I'm just guessing here

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Detect if game is build in debug or release mode?

Post by LuX » June 16th, 2012, 7:36 pm

A quick google, and turns out there is. I think....
Have a look: Link
ʕ •ᴥ•ʔ

EdadTace
Posts: 32
Joined: April 22nd, 2012, 10:28 am

Re: Detect if game is build in debug or release mode?

Post by EdadTace » June 16th, 2012, 8:06 pm

great thanks :D

I did try to google it, but I couldn't find anything

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

Re: Detect if game is build in debug or release mode?

Post by chili » June 16th, 2012, 11:51 pm

If you use the #define macro NDEBUG together with the #ifdef or #ifndef preprocessor directives, you can create code that conditionally compiles depending on which build configuration you have selected. So you can make it so that the god mode or whatever doesn't get included in the Release configuration.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Detect if game is build in debug or release mode?

Post by Asimov » June 17th, 2012, 11:23 am

Hi,

The way I would do this is to create a bool linked to a key on your keyboard.

bool Godmode=false;

Then you just stick an if statement in to turn on godmode if you press say F9.

You can easily remove this when you make the release version.

A lot of full commercial games leave it in when it goes to release like in the old Doom where you can turn on things to walk through walls and stuff.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

EdadTace
Posts: 32
Joined: April 22nd, 2012, 10:28 am

Re: Detect if game is build in debug or release mode?

Post by EdadTace » June 17th, 2012, 11:38 am

yes that's what along the idea of what I'm planning asimov, but I'd like to be able to lock it so that players can't abuse it - which I can easily do through a bool called debugMode and when that's true it allow for different debug options, such as godmode or a debugging screen with different infomation.

BUT I know myself well enough to know that I'm gonna forget to set that to false when building for release, so if I could create a way that would automaticly detect it that would be really great


So I've set up a little test, of how I've understood it should be, but it doesn't appear to be working

Code: Select all

#include <iostream>

using namespace std;

#ifdef NDEBUG
	#define debugMode false;
#else
	#define debugMode true
#endif

void main()
{
	if( debugMode )
	{
		cout << "Debug" << endl;
	}
	else
	{
		cout << "Release" << endl;
	}

	cin.get();
}
idea is that it'll tell me when it's on debug and when it's on release, but it always tells me it's debugging, so obiously I've misunderstood how I'm suppose to use this ^^'

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

Re: Detect if game is build in debug or release mode?

Post by chili » June 17th, 2012, 12:09 pm

Lose the semicolon:
#define debugMode false;
Chili

EdadTace
Posts: 32
Joined: April 22nd, 2012, 10:28 am

Re: Detect if game is build in debug or release mode?

Post by EdadTace » June 17th, 2012, 12:38 pm

same result as before - telling me it's debug in both debug and release build configuration

from my experience it doesn't actully seem to matter whether or not there is a ; after a preprocessor (think that's what they're called right?)

Post Reply