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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-26-2010, 01:42 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 139
sumosumo84 is on a distinguished road
Default problem with BOOLs

Code:
@implementation Store

@synthesize storeScrollView;

- (void) viewWillAppear:(BOOL)animated {
	credits = [[NSUserDefaults standardUserDefaults] integerForKey:@"credits"];
	creditCount.text = [NSString stringWithFormat:@"you have %i credits", credits];
	NSLog(@"%i",credits);
	bGreenBG = [[NSUserDefaults standardUserDefaults] boolForKey:@"bGreenBG"];
	greenBGAp = [[NSUserDefaults standardUserDefaults] boolForKey:@"greenBGAp"];
	bBlueBG = [[NSUserDefaults standardUserDefaults] boolForKey:@"bBlueBG"];
	blueBGAp = [[NSUserDefaults standardUserDefaults] boolForKey:@"blueBGAp"];
	bRedBG = [[NSUserDefaults standardUserDefaults] boolForKey:@"bRedBG"];
	redBGAp = [[NSUserDefaults standardUserDefaults] boolForKey:@"redBGAp"];

	[self onOff];
}
	

- (IBAction) gotoMainMenu{
	
	[self dismissModalViewControllerAnimated:YES];
}

//green bg vvvv
- (IBAction) greenBG{
	
	if (bGreenBG != TRUE) {
		credits = [[NSUserDefaults standardUserDefaults] integerForKey:@"credits"];
		
		if (credits > 10) {
			
			credits = credits - 10;
			
			NSLog(@"credits are %i",credits);
			[[NSUserDefaults standardUserDefaults] setInteger:credits forKey:@"credits"];
			
			creditCount.text = [NSString stringWithFormat:@"you have %i credits", credits];
			bGreenBG = TRUE;
			[[NSUserDefaults standardUserDefaults] setBool:bGreenBG forKey:@"bGreenBG"];
		} else {
			[self.view addSubview:lowCreditWarning];
			lowCreditWarning.frame = CGRectMake(35.0, 105.0, lowCreditWarning.frame.size.width, lowCreditWarning.frame.size.height);
		}
	} 
}


//green bg ^^^

//blue bg vvvv
- (IBAction) blueBG{
	
	if (bBlueBG != TRUE) {
		credits = [[NSUserDefaults standardUserDefaults] integerForKey:@"credits"];
		
		if (credits > 100) {
			
			credits = credits - 100;
			
			NSLog(@"credits are %i",credits);
			[[NSUserDefaults standardUserDefaults] setInteger:credits forKey:@"credits"];
			
			creditCount.text = [NSString stringWithFormat:@"you have %i credits", credits];
			bBlueBG = TRUE;
			[[NSUserDefaults standardUserDefaults] setBool:bBlueBG forKey:@"bBlueBG"];
		} else {
			[self.view addSubview:lowCreditWarning];
			lowCreditWarning.frame = CGRectMake(35.0, 105.0, lowCreditWarning.frame.size.width, lowCreditWarning.frame.size.height);
		}
	} 
}


//blue bg ^^^

//red bg vvvv
- (IBAction) redBG{
	
	if (bRedBG != TRUE) {
		credits = [[NSUserDefaults standardUserDefaults] integerForKey:@"credits"];
		
		if (credits > 1000) {
			
			credits = credits - 1000;
			
			NSLog(@"credits are %i",credits);
			[[NSUserDefaults standardUserDefaults] setInteger:credits forKey:@"credits"];
			
			creditCount.text = [NSString stringWithFormat:@"you have %i credits", credits];
			bRedBG = TRUE;
			[[NSUserDefaults standardUserDefaults] setBool:bRedBG forKey:@"bRedBG"];
		} else {
			[self.view addSubview:lowCreditWarning];
			lowCreditWarning.frame = CGRectMake(35.0, 105.0, lowCreditWarning.frame.size.width, lowCreditWarning.frame.size.height);
		}
	} 
}
Basically these are items in a store.
these items depend on bColorBG being false if they have not bought it.

But it seams that as i make new items to the store and i go to it, they are already bought! (aka bColorBG is TRUE)

how can i make it so all of the bColorBG variables are false on first launch and untill they buy it?
sumosumo84 is offline   Reply With Quote
Old 10-26-2010, 02:53 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 4
ekba89 is on a distinguished road
Default

You are taking bool values from user defaults. So there is only one bool value not for every item in the store which means if you buy one item all items' bool values will be true. You should have item class which contains some attribute for controlling if the item sold.
ekba89 is offline   Reply With Quote
Old 10-26-2010, 03:06 AM   #3 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

You should use YES & NO values for the bools.
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 10-26-2010, 12:44 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 139
sumosumo84 is on a distinguished road
Default

does changing TRUE to YES do anything?

basically i am just asking how can i set those BOOLs to false untill they are bought? because if i put bColorBG (when i say bColorBG i am just saying its one of the BOOLs i am using so it could mean bBlueBG or bGreenBG)

i heard somewhere that BOOLs at first are not set to anything so i will try

Code:
if (bGreenBG != 1 && bGreenBG != 0){
        bGreenBG = FALSE;
}
sumosumo84 is offline   Reply With Quote
Old 10-26-2010, 02:51 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

BOOLs are just integers. When they appear all by themselves they take the logicial value of "true" if they are non-zero as an integer and "false" if they are zero. You should never compare one BOOL with another. That is because the number 2 and the number 3 are both "true" as BOOLs, but if you compare them, the comparison will say they are not the same (because 2 does not equal 3). Now as a matter of fact, the compiler normally establishes a standard value for TRUE or YES, and it is usually the number 1. But you should not count on it. It is risky programming. Instead try to use only logical operators when dealing with BOOLs, like &&, ||, and "!". Don't use == or !=. Instead of

bGreenBG != 1

You should say

!bGreenBG (meaning bGreenBG is false)

And instead of

bGreen != 0

You should say just

bGreenBG (meaning bGreenBG is true)
RLScott is offline   Reply With Quote
Reply

Bookmarks

Tags
bool, code, logical error, runtime error, store

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: 331
14 members and 317 guests
7twenty7, chiataytuday, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, mistergreen2011, mottdog, palme2elie, Paul Slocum, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,660
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, laureix68
Powered by vBadvanced CMPS v3.1.0

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