About Store Forum Documentation Contact
Donations:
392$/mo



Post Reply 
Loading game from main menu
Author Message
unforgivenhero Offline
Member

Post: #1
Loading game from main menu
Hey everyone, I'm having a bit of trouble loading a saved game from my main menu. Basically, I have all the saving and loading functionality programmed in my game.cpp file. However, I want to be able to load a save from my menu.cpp file.

I need to have a saved file load and the state switch to StateGame when the user clicks the load game button. I've tried loading a save file while in StateMenu and then switching states to StateGame but this didn't work.

Anyone have any ideas on how to do this? Thanks in advance, I can supply more information if needed.
07-29-2011 01:51 PM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #2
RE: Loading game from main menu
switch to state game after pressing the load game button, and once it is in the game state, load the saved file
07-29-2011 08:31 PM
Find all posts by this user Quote this message in a reply
unforgivenhero Offline
Member

Post: #3
RE: Loading game from main menu
should i write the line of code to load the saved game inside the menu.cpp file or the game.cpp one? Because I've tried loading the game.cpp file then hitting the F3 key to load the game but it doesn't work.
07-29-2011 09:01 PM
Find all posts by this user Quote this message in a reply
PRG3D Offline
Member

Post: #4
RE: Loading game from main menu
Show some source code.
07-29-2011 09:34 PM
Find all posts by this user Quote this message in a reply
unforgivenhero Offline
Member

Post: #5
RE: Loading game from main menu
Here is the function of the load button from the main menu:

Code:
static void Load   (Ptr) {MM.window1.fadeOut() ,
                             MO.window.fadeOut(),
                             MC.window.fadeOut(),
                             Ms.hide().clip(NULL,1),
                             StateGame.set(),
                             Game::World.load("save 0.sav");}

So I set the active state to game and call the load function but it is not working.
07-29-2011 10:16 PM
Find all posts by this user Quote this message in a reply
PRG3D Offline
Member

Post: #6
RE: Loading game from main menu
Maybe in StateGame Init write Game::World.load("save 0.sav"); and other functions to load your game.
07-29-2011 10:23 PM
Find all posts by this user Quote this message in a reply
unforgivenhero Offline
Member

Post: #7
RE: Loading game from main menu
Hmm that might work but what happens if someone wants to disregard their old saved game and start a new game? I'm thinking about trying an if then statement in the update part of StateGame that will load a game if the load button was clicked. But this might have performance issues.
07-29-2011 10:29 PM
Find all posts by this user Quote this message in a reply
PRG3D Offline
Member

Post: #8
RE: Loading game from main menu
(07-29-2011 10:29 PM)unforgivenhero Wrote:  Hmm that might work but what happens if someone wants to disregard their old saved game and start a new game?

You can get info about it in some variable. Create something like it:

Code:
struct Info
{
Bool _newGame;

Info(){newGame = false;};
}extern info;

//and into menu.cpp
info._newGame = userChoice; //if load then false
StateGame.set();

You can also create LevelManager (lm.load(Str) / lm.save(str) / lm.new() etc.)
07-29-2011 11:02 PM
Find all posts by this user Quote this message in a reply
unforgivenhero Offline
Member

Post: #9
RE: Loading game from main menu
ok ill try this. thanks!
07-30-2011 12:11 AM
Find all posts by this user Quote this message in a reply
Post Reply