Advice for simple 2D game

Started by
24 comments, last by Satharis 9 years, 4 months ago

"IntelliSense: a nonstatic member reference must be relative to a specific object"

That error seems to imply you did this:


//INVALID CODE:
class MyClass
{
    public:
    
    int myVariable;
    
    static void MyFunction()
    {
        //... code that uses 'myVariable'...
    }
};

In this example, 'myVariable' isn't a global. It is a member-variable that belongs to one specific "instance" of that class.

The function 'MyFunction()' on the other hand, is 'static' which means it doesn't belong to any specific "instance".

Functions that are static can't use member-variables that aren't static.

This is a little confusing, but as you keep learning about classes and also keep testing code yourself, you'll come to understand it.

There's a difference between a type of class (like "class Dog" is a new 'Dog' type of class) and an instance of a class ("Dog fluffy;" is an instance of the Dog class, named fluffy). The difference between a type and an instance is an important difference, but it took me awhile to learn it when I first started programming. smile.png


Dog fluffy = ...
int currentYear = 2014;

'int' is a type of variable. 'Dog' is a type of variable.

'currentYear' is a specific instance of an 'int'. 'fluffy' is a specific instance of a 'Dog'.

Advertisement

I'd like to take the time to post and show my gratitude towards your guy's post! Even though these post weren't directed at me, it very much helped and motivated me to keep going on my way to game development. I too, am at this point creating text-based games and about to transition over to developing 2D applications and games! Thank you all!This is actually my first post, but I've been browsing these forums for a while now!

make it fast , responsive and simple

I see!!

Well since i learned some new stuff i tried to rewrite all my code in the RPG to tailor suit the description you taught me.
It has helped me ALOT and i finally understand how classes work for the most part!

But the thing is that i want to make the player able to enter his name, then be able to call the name through out the other dialoges in the game.

I also want to access the Profession integer so that your able to advance classes from adventurer to knight or priest for example.

I find that if i initilize it inside a function in another .cpp im not able to retrive that integer from all my files unless its a global in a .h file.

And that's where i met the problem you corrected me on earlier.

Glad to hear that Mesmaroth!
If you'd like, mabey we could study together and share thoughts with each other?
I know i learn faster when i hear others thoughts and opinions.

Unity3diy
Yeah sorry about that! im trying to be as active as i can!
But work and trying to learn what Servant taught me has pulled me away from the post from time to time.
But feel free to use this topic if you also have any thoughts or problems.
We could all help each other out! :)

You have to pass the class over when you call your next function ie
<code> myFunction(myclass);</code>

Yeah sorry about that! im trying to be as active as i can!

I think he was suggesting to design your game to be 'fast, responsive, and simple'. wink.png

Ahh! ofcourse!
Pardon my confused brain.

Anyhow, i tried to install SFML on Visual Studio 13.
I know that the latest version of SFML isn't compatible with Visual 13.
So i tried using Cmake, everything went on smooth untill i stumbled upon this Error:

Error 1 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup C:\documents\visual studio 2013\Projects\sfml 2.0\sfml 2.0\MSVCRTD.lib(crtexew.obj)
Error 2 error LNK1120: 1 unresolved externals C:\documents\visual studio 2013\Projects\sfml 2.0\Debug\sfml 2.0.exe

Im not sure what ive done wrong, might it be that ive included wrong library's?
I know i atleast included SFML_STATIC in the C++ Preprocessor that many seem to miss.

Ahh! ofcourse!
Pardon my confused brain.
Anyhow, i tried to install SFML on Visual Studio 13.
I know that the latest version of SFML isn't compatible with Visual 13.
So i tried using Cmake, everything went on smooth untill i stumbled upon this Error:

Error 1 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup C:\documents\visual studio 2013\Projects\sfml 2.0\sfml 2.0\MSVCRTD.lib(crtexew.obj)
Error 2 error LNK1120: 1 unresolved externals C:\documents\visual studio 2013\Projects\sfml 2.0\Debug\sfml 2.0.exe
Im not sure what ive done wrong, might it be that ive included wrong library's?
I know i atleast included SFML_STATIC in the C++ Preprocessor that many seem to miss.

I would expect it to not work on a visual studio version that doesn't exist. If you meant 2013, well it is compatible.. they just don't have pre-built binaries for it, you have to do it yourself.

As for the error, your project settings under linker->system->subsytem are set to Windows, which means the linker is trying to find the WinMain entry point, I'm assuming you wrote a main function instead.

You can change the subsystem to console to solve that, that will make it spawn a console window and call main, all the SFML code will still work fine, it can still create a window and all that. Alternatively SFML comes with a little library you can add to the linker input called sfml-main.lib, all that really does is provide a winmain function that calls the standard main function, so just by adding it to the linker input you can use your standard main function even if the subsystem is set to Windows.

This topic is closed to new replies.

Advertisement