Jump to content

Need help with my game (noob asks for help)

- - - - -

  • Please log in to reply
4 replies to this topic

#1
cepa

cepa

    Newbie

  • Members
  • PipPip
  • 13 posts
So, I've been making a textRPG game, when the school started I scrapped the project because I don't have that much free time now, but recently I found the project and decided to continue (i just wasted your time by telling this retarded back-story :D) so anyway I started work on the battle system and got into a bit of trouble, I can't (and don't know how to) use one instance of a class in multiple functions/files. I've attached the source code below. Also any advice on the game would be helpful.

Here is my game Multiupload.com - upload your files to multiple file hosting sites!, for some odd reason, file uploader doesn't work.

#2
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
You may use a global variable if you'd like. However, many call global variables satanic devices so you might also just want to structure your program in such a way that all objects that need references to the variable have one. Take a look at the following code for what I mean on the second part
class God
{
public:
    void foo() { return; }
};

class Dog
{
public:
    void bar() { return; }
};

class Priest
{
    God & god_;
public:
    Priest(God & zgod) : god_(zgod) { /* void */ }
    void pray() { god_.foo(); }
};


#3
cepa

cepa

    Newbie

  • Members
  • PipPip
  • 13 posts
Umm, and how do I make a global instance?

#4
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
Variables. Data Types. (Under Scope of Variables)

#5
cepa

cepa

    Newbie

  • Members
  • PipPip
  • 13 posts
Ok, i added Player Hero before my main function, but i stll get an error about it being a declared variable, because "Player Hero" is in another file maybe?

EDIT: OK problem i solved the problem myself, but thanks for help. All i needed was to declare instance in main function then in other files use extern




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users