Advertisement Jump to content
Sign in to follow this  
Adam West

game state management not working?

This topic is 2422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey there again,

I am trying to create a game state manager using an input manager where a gui will appear when the user presses escape in game, for some reason its not working :(, any ideas??

#ifndef MAIN_H_
#define MAIN_H_
#include <irrlicht.h>
#include <iostream>
#include <string.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

class redNovember
// always initialize class-members in the constructor - especially set pointers to 0!
redNovember() : device(0), driver(0), smgr(0),guienv(0)

IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
ICameraSceneNode * camera;
IMetaTriangleSelector * meta;
IGPUProgrammingServices* gpu;
scene::IParticleSystemSceneNode* ps;
gui::IGUIInOutFader* fader;

void initIrrlicht();
void initFPSCamera();
void renderScene();
int shutdown();
void inputHandle();
//for the game scenes
void LoadScene(); // const chars for maps
void initSkybox(const char* up,const char* down,const char* left, const char* right, const char* front, const char* back);
void initSkydome(const char* skydomefile);
//shader stuff
void initShader();
void VertexShader(const char* VertexShaderFilename, const char* VertexShaderFunction);
void PixelShader(const char* PixelShaderFilename, const char* PixelShaderFunction);
void GeoShader(const char* GeoShaderFilename, const char* GeoShaderFunction);
void initRain();
void initFog();
void initBloom();
void initHDR();
void initSSAO();
void initBokehDOF();
//user interface and effects
bool showGameMenu;
void fadeInTransition();
void fadeOutTransition();
void showInGameMenu();
void hideInGameMenu();
//material and shader ID's

s32 bloomMaterial;
s32 bokehDOFMaterial;
//s32 CgExampleMaterialType;
//for shaders

// You can put any other variables you want in here.
// For example driver, scenemanger although you can also always get them from device
// Note that the clean solution is making variables private and use public
// get-functions to access them from other classes as you can see when looking at Irrlicht classes.
// You can for example also create a function like that:
//irr::scene::ISceneManager* getSceneManager() const { return device ? device->getSceneManager() : 0; }


// every other global you would need can instead of being global just be put in here.
class MyEventReceiver : public IEventReceiver
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
return KeyIsDown[keyCode];
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown = false;
// We use this array to store the current state of each key


#include "main.h"
#include "luamanager.h"
#include "physicsmanager.h"
LuaManager * LUA = new LuaManager;
//newtonManager* PHYS = new newtonManager;
redNovember* SYS = new redNovember;
MyEventReceiver receiver;

int redNovember::shutdown()
delete LUA;

//delete PHYS;
delete SYS;
return 0;
int main()





///put main shit in here
//put gui loop here




void redNovember::initIrrlicht()
device = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32,
false, false, true, 0);
device->setWindowCaption(L"Project: Red November");
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
device->getCursorControl()->setVisible(false); //hide cursor
fader = device->getGUIEnvironment()->addInOutFader();
// Then create the event receiver, giving it that context structure.
// And tell the device to use our custom event receiver.


void redNovember::renderScene()
int lastFPS = -1;

inputHandle(); //input handler

//add pause functions here

if (device->isWindowActive())
driver->beginScene(true, true, video::SColor(255,200,200,200));

int fps = driver->getFPS();
if (lastFPS != fps)
core::stringw str = L"[";
str += driver->getName();
str += "] FPS:";
str += fps;
lastFPS = fps;
void redNovember::inputHandle()
//menu key handler
showGameMenu = true;

//menu shit
if (showGameMenu = true)



#include "main.h"

void redNovember::fadeInTransition()
void redNovember::fadeOutTransition()
void redNovember::showInGameMenu()
std::cout << "on" << std::endl;
void redNovember::hideInGameMenu()
std::cout << "off" << std::endl;

at the moment it should spam off on the output window and then spam on when the escape key is pressed... the output only spams on though

Share this post

Link to post
Share on other sites
Define "its not working". Compiler error? Runtime crash? Unexpected behaviour? Gremlins escape from your computer?

In redNovember::inputHandle(), you are using an assignment in a conditional expression:

if (showGameMenu = true)

The first line sets showGameMenu to true, then tests if it is true (which it must be), and then executes shwoInGameMenu(). This is assuming you have no memory related errors, such as calling inputHandle() on an invalid object or uninitialised pointer.

Consider increasing your warning level until the compiler outputs a message about this. Also in future, try to fully describe the problematic behaviour. If you are getting errors or warnings, post them. If you are getting strange behaviour, post both what you expect to happen and what actually happened. Should gremlins emerge from your computer, give an estimate as to how many, what size they were and what colour.

Share this post

Link to post
Share on other sites

Define "its not working". Compiler error? Runtime crash? Unexpected behaviour? Gremlins escape from your computer?

if you read the code and the statement, the problem is it only spams the function which causes it to show, it should be off then on when escape is pressed.

Share this post

Link to post
Share on other sites

if you read the code and the statement...
There is a lot of code, and I am not familiar with Irrlicht. I don't have a large amount of time, so I skimmed the code.

... the problem is it only spams the function which causes it to show, it should be off then on when escape is pressed.
Sorry, I did miss the final sentence in your original post. Still, I cannot parse that sentence. I don't know what "to spam" a function means.

Are you trying to say that the escape key is supposed to toggle the menu? Presumably, if you are saying that then the actual behaviour is different. This is what I want to see - a clear description of what the problem is.

As I mentioned, the code as you posted will always show the menu, because you unconditionally assign showGameMenu to "true". As Matthew Wood states, you can fix it by using the double equals comparison operator. Alternatively, you can just write:

if(showGameMenu) {
// Show the menu
} else {
// Hide the menu
Edited by rip-off

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!