Erro in struct usage

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Erro in struct usage

Postby Alx101 » Sat Feb 11, 2012 7:09 pm

Hey, im having issues with my compile (Code::Blocks) Telling me i use a struct in the worng way, even tho i know you can use it that way. And if not, how do i transform a vector3di -> vector3df?
Source Code:
cpp Code: Select all
#include <irrlicht.h>
#include "driverChoice.h"
#include <iostream>
#include "lua_inc.h"
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "Irrlicht.lib")
#endif
 
class EventH : public IEventReceiver
{
public:
        struct SMouseState
        {
                core::vector3di Position;
                bool LeftButtonDown;
                bool RightButtonDown;
        } MouseState;
 
    virtual bool OnEvent(const SEvent& event)
        {
                if (event.EventType == irr::EET_KEY_INPUT_EVENT)
                        KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
 
                if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
                {
                        switch(event.MouseInput.Event)
                        {
                        case EMIE_LMOUSE_PRESSED_DOWN:
                                MouseState.LeftButtonDown = true;
                                break;
 
                        case EMIE_LMOUSE_LEFT_UP:
                                MouseState.LeftButtonDown = false;
                                break;
 
                        case EMIE_MOUSE_MOVED:
                                MouseState.Position.X = event.MouseInput.X;
                                MouseState.Position.Y = event.MouseInput.Y;
                                MouseState.Position.Z = 0;
                                break;
                        case EMIE_RMOUSE_PRESSED_DOWN:
                                MouseState.RightButtonDown = true;
                        case EMIE_RMOUSE_LEFT_UP:
                                MouseState.RightButtonDown = false;
 
                        default:
 
                                break;
                        }
                }
 
                return false;
        }
 
        virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                return KeyIsDown[keyCode];
        }
 
        EventH()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }
private:
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
 
int main()
{
    int iErr = 0;
    lua_State *lua = lua_open ();
 
    video::E_DRIVER_TYPE driverType=driverChoiceConsole();
    if (driverType==video::EDT_COUNT)
        return 1;
 
    EventH receiver;
 
    IrrlichtDevice* device = createDevice(driverType,core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
 
 
    device->setWindowCaption(L"Flare Ultimate Creation Kit");
 
    if (device == 0)
        return 1;
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
    /*video::ITexture* mS = driver->getTexture("C:/Users/Alx101/Dropbox/Echoes/GUIGameMaker/Pointer.png");*/
 
    guienv->addStaticText(L"Flare Ultimate Creation Kit",
        rect<int>(10,10,200,22), true);
 
    scene::ISceneNode * node = smgr->addSphereSceneNode();
        if (node)
        {
                node->setPosition(core::vector3df(0,0,30));
                node->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
                node->setMaterialFlag(video::EMF_LIGHTING, false);
        }
 
        scene::ISceneNode* n = smgr->addCubeSceneNode();
 
        if (n)
        {
                n->setMaterialTexture(0, driver->getTexture("../../media/t351sml.jpg"));
                n->setMaterialFlag(video::EMF_LIGHTING, false);
                scene::ISceneNodeAnimator* anim =
                        smgr->createFlyCircleAnimator(core::vector3df(0,0,30), 20.0f);
                if (anim)
                {
                        n->addAnimator(anim);
                        anim->drop();
                }
        }
 
    scene::IAnimatedMeshSceneNode* anms =
    smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/ninja.b3d"));
 
        if (anms)
        {
                scene::ISceneNodeAnimator* anim =
                        smgr->createFlyStraightAnimator(core::vector3df(100,0,60),
                        core::vector3df(-100,0,60), 3500, true);
                if (anim)
                {
                        anms->addAnimator(anim);
                        anim->drop();
                }
 
                anms->setMaterialFlag(video::EMF_LIGHTING, false);
 
                anms->setFrameLoop(0, 13);
                anms->setAnimationSpeed(15);
//              anms->setMD2Animation(scene::EMAT_RUN);
 
                anms->setScale(core::vector3df(2.f,2.f,2.f));
                anms->setRotation(core::vector3df(0,-90,0));
//              anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
 
        }
    /*core::position2d<s32> m = device->getCursorControl()->getPosition();*/
    scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();
    device->getCursorControl()->setVisible(true);
    /*guienv->addImage(mS, position2d<s32>(m.X, m.Y), false, 0, 1, 0);*/
    int lastFPS = -1;
    float mX = receiver.SMouseState.Position.X;
 
 
    u32 then = device->getTimer()->getTime();
 
        // This is the movemen speed in units per second.
    const f32 MOVEMENT_SPEED = 10.f;
        while(device->run())
        {
 
                // Work out a frame delta time.
                //core::vector3df
                const u32 now = device->getTimer()->getTime();
                const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
                then = now;
                core::vector3df nodePosition = node->getPosition();
                   // camera->setPosition(core::vector3df());
                /*if(receiver.IsKeyDown(irr::KEY_KEY_W))
                        nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_S))
                        nodePosition.Z -= MOVEMENT_SPEED * frameDeltaTime;
 
                if(receiver.IsKeyDown(irr::KEY_KEY_E))
                    nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
                if(receiver.IsKeyDown(irr::KEY_KEY_Q))
                    nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
 
                if(receiver.IsKeyDown(irr::KEY_KEY_A))
                        nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_D))
                        nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;*/

                if(receiver.IsKeyDown(irr::KEY_ESCAPE))
                   device->closeDevice();
 
                //core::position2d<s32> m = device->getCursorControl()->getPosition();
                node->setPosition(nodePosition);
                driver->beginScene(true, true, video::SColor(255,113,113,133));
 
                smgr->drawAll(); // draw the 3d scene
                device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
 
                driver->endScene();
 
                int fps = driver->getFPS();
 
                if (lastFPS != fps)
                {
                        core::stringw tmp(L"[");
                        tmp += driver->getName();
                        tmp += L"] fps: ";
                        tmp += fps;
 
                        device->setWindowCaption(tmp.c_str());
                        lastFPS = fps;
                }
 
        }
 
    device->drop();
    return 0;
}
 

The Error:
cpp Code: Select all
E:\VirusGL\Game Editor\main.cpp: In function 'int main()':
E:\VirusGL\Game Editor\main.cpp:162: error: invalid use of 'struct EventH::SMouseState'
 
Alx101
 
Posts: 15
Joined: Sat Feb 11, 2012 7:04 pm

Re: Erro in struct usage

Postby REDDemon » Sat Feb 11, 2012 7:32 pm

yes you are just declaring the struct SMouseState withtou using it. You must declare a member variable like
cpp Code: Select all
 
SMouseState myMouseState;
 

if you want to use that struct
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 859
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Erro in struct usage

Postby serengeor » Sat Feb 11, 2012 7:34 pm

REDDemon wrote:yes you are just declaring the struct SMouseState withtou using it. You must declare a member variable like
cpp Code: Select all
 
SMouseState myMouseState;
 

if you want to use that struct


Doesn't this do that:
cpp Code: Select all
struct SMouseState
        {
                core::vector3di Position;
                bool LeftButtonDown;
                bool RightButtonDown;
        } MouseState; <-------------
 


Never used it myself like this, but I think that it does the job.
Working on game: Marrbles (Currently stopped).
User avatar
serengeor
 
Posts: 1711
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Erro in struct usage

Postby LukeBitts » Sat Feb 11, 2012 8:36 pm

No, that just creates an alias for your struct, so instead of using SMouseState varname; you use MouseState varname;
User avatar
LukeBitts
 
Posts: 21
Joined: Fri Apr 22, 2011 6:02 am

Re: Erro in struct usage

Postby serengeor » Sat Feb 11, 2012 8:48 pm

LukeBitts wrote:No, that just creates an alias for your struct, so instead of using SMouseState varname; you use MouseState varname;

I see, whats the point of using this then?
That is just equivalent to:
cpp Code: Select all
typedef SMouseState MouseState;
?
Working on game: Marrbles (Currently stopped).
User avatar
serengeor
 
Posts: 1711
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Erro in struct usage

Postby LukeBitts » Sat Feb 11, 2012 9:01 pm

I'm not sure, I think in C, to instance a struct, you had to do a lot more than just "MyStruct struct" and giving it an alias made it easier. C++ probably keeps it for backwards compatibility.

Again, I'm not really sure, could be for some other reason.

edit: Now I'm feeling kinda dumb, I just read somewhere that your code is suposed to work, sorry for the wrong info, I have no idea what's wrong with your code :/
User avatar
LukeBitts
 
Posts: 21
Joined: Fri Apr 22, 2011 6:02 am

Re: Erro in struct usage

Postby Alx101 » Sat Feb 11, 2012 10:15 pm

Well i can't define it, because its inside a class. And i cant do receiver.MouseState.LeftMousetc. Because it wont let me. And i can't use receiver.SMouseState.LeftMouseButton because it won't let me! :? WHAT IS WRONG HERE! I guess i could make it in another way, making a class that inherits from the main one, but have never done that. Any ideas?

Ps. Thanks for all the help so far!
Alx101
 
Posts: 15
Joined: Sat Feb 11, 2012 7:04 pm

Re: Erro in struct usage

Postby serengeor » Sat Feb 11, 2012 11:02 pm

You can define it, as you already did. You just didn't declare a variable that could be used.
Do
MouseState state;

and use 'state'.
Working on game: Marrbles (Currently stopped).
User avatar
serengeor
 
Posts: 1711
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Erro in struct usage

Postby REDDemon » Sun Feb 12, 2012 8:29 am

in c++ a struct is the same of a class if it helps to you. Nothing todo with C's structs. the only difference is that a Struct members are by default public while in a Class members are by default private. you can ineriht a struct from a class and viceversa. you can use struct with virtual functions etc.. (different from C# in wich structs are different from classes).
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 859
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Erro in struct usage

Postby Alx101 » Sun Feb 12, 2012 2:23 pm

serengeor wrote:You can define it, as you already did. You just didn't declare a variable that could be used.
Do
MouseState state;

and use 'state'.


I have tried that but it won't let me use it's member functions XC
Alx101
 
Posts: 15
Joined: Sat Feb 11, 2012 7:04 pm

Re: Erro in struct usage

Postby Alx101 » Sun Feb 12, 2012 2:57 pm

I have done some changed wich fixed the problem. First i tried to make a mouse class and friend it to the EventH but it wouldnt work, neither if it inheritaged (sorry for bad english) from the EventH. So i declared the struct outsid of the calss, it works. But only one problem XC
cpp Code: Select all
#include <irrlicht.h>
#include "driverChoice.h"
#include <iostream>
#include "lua_inc.h"
 
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "Irrlicht.lib")
#endif
 
struct Mouse
{
    bool leftButton;
    bool rightButton;
    core::vector3df Position;
}
 
class EventH : public IEventReceiver
{
    public:
        Mouse mouse;
        virtual bool OnEvent(const SEvent& event)
            {
                if (event.EventType == irr::EET_KEY_INPUT_EVENT)
                        KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
 
                if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
                {
                        switch(event.MouseInput.Event)
                        {
                        case EMIE_LMOUSE_PRESSED_DOWN:
                                //MouseState.LeftButtonDown = true;
                                mouse.leftButton = true;
                                break;
 
                        case EMIE_LMOUSE_LEFT_UP:
                                //MouseState.LeftButtonDown = false;
                                mouse.leftButton = false;
                                break;
 
                        case EMIE_MOUSE_MOVED:
                                /*MouseState.Position.X = event.MouseInput.X;
                                MouseState.Position.Y = event.MouseInput.Y;
                                MouseState.Position.Z = 0;*/

                                mouse.Position.X = event.MouseInput.X;
                                mouse.Position.Y = event.MouseInput.Y;
                                mouse.Position.Z = 0;
                                break;
                        case EMIE_RMOUSE_PRESSED_DOWN:
                                //MouseState.RightButtonDown = true;
                        case EMIE_RMOUSE_LEFT_UP:
                                //MouseState.RightButtonDown = false;
 
                        default:
 
                                break;
                        }
                }
 
                return false;
        }
 
        virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                return KeyIsDown[keyCode];
        }
 
        EventH()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }
    private:
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
}; (<-- HERE IS THE ERROR, AND THIS WAS NOT IN THE CODE)
 
 
int main()
{
    int iErr = 0;
    lua_State *lua = lua_open ();
 
    video::E_DRIVER_TYPE driverType=driverChoiceConsole();
    if (driverType==video::EDT_COUNT)
        return 1;
 
    EventH receiver;
    Mouse mS;
    IrrlichtDevice* device = createDevice(driverType,core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
 
 
    device->setWindowCaption(L"Flare Ultimate Creation Kit");
 
    if (device == 0)
        return 1;
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
    /*video::ITexture* mS = driver->getTexture("C:/Users/Alx101/Dropbox/Echoes/GUIGameMaker/Pointer.png");*/
 
    guienv->addStaticText(L"Flare Ultimate Creation Kit",
        rect<int>(10,10,200,22), true);
 
    scene::ISceneNode * node = smgr->addSphereSceneNode();
        if (node)
        {
                node->setPosition(core::vector3df(0,0,30));
                node->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
                node->setMaterialFlag(video::EMF_LIGHTING, false);
        }
 
        scene::ISceneNode* n = smgr->addCubeSceneNode();
 
        if (n)
        {
                n->setMaterialTexture(0, driver->getTexture("../../media/t351sml.jpg"));
                n->setMaterialFlag(video::EMF_LIGHTING, false);
                scene::ISceneNodeAnimator* anim =
                        smgr->createFlyCircleAnimator(core::vector3df(0,0,30), 20.0f);
                if (anim)
                {
                        n->addAnimator(anim);
                        anim->drop();
                }
        }
 
    scene::IAnimatedMeshSceneNode* anms =
    smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/ninja.b3d"));
 
        if (anms)
        {
                scene::ISceneNodeAnimator* anim =
                        smgr->createFlyStraightAnimator(core::vector3df(100,0,60),
                        core::vector3df(-100,0,60), 3500, true);
                if (anim)
                {
                        anms->addAnimator(anim);
                        anim->drop();
                }
 
                anms->setMaterialFlag(video::EMF_LIGHTING, false);
 
                anms->setFrameLoop(0, 13);
                anms->setAnimationSpeed(15);
//              anms->setMD2Animation(scene::EMAT_RUN);
 
                anms->setScale(core::vector3df(2.f,2.f,2.f));
                anms->setRotation(core::vector3df(0,-90,0));
//              anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
 
        }
    /*core::position2d<s32> m = device->getCursorControl()->getPosition();*/
    scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();
    device->getCursorControl()->setVisible(true);
    /*guienv->addImage(mS, position2d<s32>(m.X, m.Y), false, 0, 1, 0);*/
    int lastFPS = -1;
 
    u32 then = device->getTimer()->getTime();
 
    const f32 MOVEMENT_SPEED = 10.f;
        while(device->run())
        {
                const u32 now = device->getTimer()->getTime();
                const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
                then = now;
                core::vector3df nodePosition = node->getPosition();
                core::vector3df cameraPos = camera->getPosition();
                   // camera->setPosition(core::vector3df());
                /*if(receiver.IsKeyDown(irr::KEY_KEY_W))
                        nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_S))
                        nodePosition.Z -= MOVEMENT_SPEED * frameDeltaTime;
 
                if(receiver.IsKeyDown(irr::KEY_KEY_E))
                    nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
                if(receiver.IsKeyDown(irr::KEY_KEY_Q))
                    nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
 
                if(receiver.IsKeyDown(irr::KEY_KEY_A))
                        nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_D))
                        nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;*/

                if(receiver.IsKeyDown(irr::KEY_ESCAPE))
                   device->closeDevice();
                if(mS.leftButton)
                    cameraPos = mS.Position;
 
                //core::position2d<s32> m = device->getCursorControl()->getPosition();
                node->setPosition(nodePosition);
                driver->beginScene(true, true, video::SColor(255,113,113,133));
 
                smgr->drawAll(); // draw the 3d scene
                device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
 
                driver->endScene();
 
                int fps = driver->getFPS();
 
                if (lastFPS != fps)
                {
                        core::stringw tmp(L"[");
                        tmp += driver->getName();
                        tmp += L"] fps: ";
                        tmp += fps;
 
                        device->setWindowCaption(tmp.c_str());
                        lastFPS = fps;
                }
 
        }
 
    device->drop();
    return 0;
}
 

Thats the new code

The error:
cpp Code: Select all
E:\VirusGL\Game Editor\main.cpp|82|error: multiple types in one declaration|

The error occurs at the end very end of the EventH class.
Alx101
 
Posts: 15
Joined: Sat Feb 11, 2012 7:04 pm

Re: Erro in struct usage

Postby CuteAlien » Sun Feb 12, 2012 3:05 pm

Your struct Mouse is missing a ; at the end. Please check your code careful before asking for help... if you get stuck then reduce it! Reduce it unless nothing but the single line that goes wrong is left if you have to. You can't go on and ask for help in every simply syntax-problem you run into.

edit: What might help: Compilers always work from top-to-bottom through your files. Which means you only have to check the line you have the error in and those before the error. So just get rid of so many lines before your error until you see what the problem is. This is a technique you will use throughout your programming career. Divide and Conquer - if you don't see your error divide your sources some more. If error goes away while removing lines add them again until you have the error again and try removing other lines etc.
IRC: #irrlicht on irc.freenode.net
My Irrlicht code snippets: https://code.google.com/p/irr-playground-micha/
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Play a fun racer created with Irrlicht: http://www.irrgheist.com/
User avatar
CuteAlien
Admin
 
Posts: 6556
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Erro in struct usage

Postby Alx101 » Sun Feb 12, 2012 3:10 pm

Thanks! Sorry, i looked it throught but im very tired as of now, and i forgot the error checking progress. Thanks again!
Alx101
 
Posts: 15
Joined: Sat Feb 11, 2012 7:04 pm


Return to Beginners Help

Who is online

Users browsing this forum: Google [Bot] and 1 guest