Design/Inheritance issue

Hello,

I am programming a text-based RPG and I am having a little bit of an issue with being able to access data in a given derived class.

I have designed the game to function using a Game class, which holds a State class pointer called currentState. I have then derived several classes from the state class making classes such as StartupState, ShutdownState, CharcreationState, MainmenuState, etc. in my main game loop, the game object makes a call to its update function which makes a call to the currentStates update function.

Based on the state it is in (using virtual function overloads) it calls the appropriate update function which in turn allows me to execute whatever code I want.

My problem exists in the character creation state... The game object also holds a pointer to an Entity. I am deriving actual player archtypes (such as Fighter, or Mage) from the Entity class. So all in all that all seems to be fine.

But I am having trouble getting the state machine to do the work of making the character and then setting the Game object Entity pointer = to that player.

I tried giving the CharcreationState some extra variables to hold player data, and then within the main game loop use logic to catch the right moment when I could call a Game function called createPlayer(). This function could then use the Games State pointer and and set the player pointers data using the accessors provided with the CharcreationState. The problem with this is that I am dealing with a State pointer... Even though I know I have a pointer to a CharcreationState object it is acting like a State... Because of this I cannot use its accessors.

I believe I could just bloat up my main game loop in order to create the character and get everything assigned. But I implemented the State-machine so I could keep the game loop very minimal and allow the machine to drive the game. So I would like to see if anyone has any idea's on how I can make this happen.

I am sorry if this is confusing. I hope I gave enough information on how I am "designing" the game tech-wise in order to receive some idea's that may solve my issues with scope from inheritance.

Also, if you absolutely need code, let me know. I tried to explain it well enough so you would not have to read code. There are a lot of files and classes in this game and I was hoping a good write-up would be enough of an explanation

Thanks in advance,

~Knight
I was looking around the forums for RPG posts and I saw one where a person under the tag of knight01 posts basically requesting someone to program an RPG for him and give him the code.

I just wanted people to know I am not this user. My last name is knight, so that is why I sign off with it.

I will continue to search for some possible fixes for my issues above, and continue to update this thread if I do find a fix.

~Knight
I am a little bit confused by your description. You have a character creation state, but there is logic in the game that tells you when to create players, passing in the current state. Why isn't the CharcreationState making that decision for itself?

Is createPlayer() only called within the CharcreationState? If so, it could take a CharcreationState* as an argument rather than a State*.

Some code, with judicious removal of unimportant parts, would be helpful. Espcially the main loop, State, CharcreationState and the createPlayer function, whereever that is. Possibly Game, too.
Ok i had a post written up and when I went to post it, it failed. So anyway, i solved the problem by passing pointers for the info into CharcreationState and then using that gathered info to call my game's createPlayer() function and have it build the character based on what class it is etc..


I realize explaining something that complicated with words just wont cut it, especially with how complicated the flow of a game is. Next time I will just post code immediately in order to give you guys a better understanding of my question. I know how frustrating it can be to try to help someone when they do not present their problem clearly.

Sorry doug4. Thanks for the input though.
Topic archived. No new replies allowed.