Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-14-2012, 10:31 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 12
Zanzibar7 is on a distinguished road
Default my bool loses its value, need help

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?

Last edited by Zanzibar7; 01-15-2012 at 03:05 AM.
Zanzibar7 is offline   Reply With Quote
Old 01-16-2012, 10:20 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

New instance (alloc init) = new variables. The app delegate works because it is a singleton, you aren't creating a new instance of it.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 386
8 members and 378 guests
apatsufas, comicool, dansparrow, husthlj, LunarMoon, mer10, Murphy, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0