In the game I'm making I have a main menu view which has a new game button and a load game button, which both send you to the load game view. Then in the load game view I have a start button, and I want that button to send you to one of two views depending on whether you pushed the new game button or the load game button in the main menu.
Right now I have a Bool that becomes true when the new game button is pressed and false when the load game button is pressed. Then I have a method in the main menu that returns the value of the bool when it gets called, so when the start button in the load view is pressed, it calls that method.
My problem is that somewhere in between pressing the new game or load game buttons, and when I call the method, the value of the bool gets lost and it becomes false.
Here is some of my code:
Code:
@interface MenuViewController : UIViewController {
BOOL newGameWasClicked;
}
@property (nonatomic) BOOL newGameWasClicked;
- (IBAction)newGameButtonClicked;
- (IBAction)loadGameButtonClicked;
- (BOOL)isNewGameSelected:(BOOL) newGameBool;
@end
Code:
@implementation MenuViewController
@synthesize newGameWasClicked;
- (BOOL)isNewGameSelected:(BOOL) newGameBool {
return newGameWasClicked;
}
- (IBAction)newGameButtonClicked {
newGameWasClicked = true;
[gAppDelegate goToLoadGame];//goToLoadGame is a method i created
} //in my app delegate that removes the
- (IBAction)loadGameButtonClicked { //menu view and adds the load view to
newGameWasClicked = false; //the window
[gAppDelegate goToLoadGame];
}
@end
Code:
@interface LoadViewController : UIViewController {
BOOL newGameIsSelected;
}
@property (nonatomic) BOOL newGameIsSelected;
- (IBAction)startButtonPressed;
@end
Code:
@implementation LoadViewController
@synthesize newGameIsSelected;
- (IBAction)startButtonPressed {
MenuViewController *menuController = [[MenuViewController alloc] init];
[menuController isNewGameSelected: newGameIsSelected];
if (newGameIsSelected == true) {
NSLog(@"going to character creation");
}
else {
NSLog(@"going to town");
}
[menuController release];
}
newGameWasClicked always seems to be false when the method isNewGameSelected gets called. How can I fix this, or is there a better way of doing it?
Also, am I calling/using my method correctly?
EDIT: Well, I got it to work. Instead of calling a method in the load game view controller, I imported my AppDelegate and used gAppDelegate.menuController.newGameWasClicked. Now i don't need the method isNewGameSelected or the bool newGameIsSelected. This is so much simpler than I was making it.
I'm glad that I figured it out, but I don't know why this way works and the other way doesn't. Can someone explain to me why going through my app delegate to get to this variable worked, but not calling a method from the class to get the value?