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 06-13-2010, 10:19 AM   #1 (permalink)
Cool Person
 
Join Date: Jun 2010
Location: Minnesota
Posts: 66
mitchsamuels is on a distinguished road
Send a message via Skype™ to mitchsamuels
Default Help- Scoring with UILabel

I am so confused. I have tried everything I can think of.

Can someone help me out with scoring,

I want it so every time someone touches the screen, a UILabel (player_Score) increases by one number every touch.
Could someone post the code?

Sorry, I am new to Xcode and everything.
mitchsamuels is offline   Reply With Quote
Old 06-13-2010, 04:52 PM   #2 (permalink)
Registered Member
 
Mjsdabeast's Avatar
 
Join Date: Oct 2009
Location: Illinois
Age: 16
Posts: 94
Mjsdabeast is on a distinguished road
Smile

Quote:
Originally Posted by mitchsamuels View Post
I am so confused. I have tried everything I can think of.

Can someone help me out with scoring,

I want it so every time someone touches the screen, a UILabel (player_Score) increases by one number every touch.
Could someone post the code?

Sorry, I am new to Xcode and everything.
You could use this.
Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
        //called whenever someone touches screen
	UITouch *touch = [[event allTouches] anyObject];
        

        //setup an int score in .h and use it like this
        score += 1;

       //setup a label and string that the label displays
       NSString *string = [[NSString alloc] initWithFormat:@"%d", score];
       // make a label called label
       label.text = string;
       [string release];
       
}
Hope this helps

Last edited by Mjsdabeast; 06-13-2010 at 04:55 PM.
Mjsdabeast is offline   Reply With Quote
Old 06-13-2010, 11:11 PM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 35
SynSoft is on a distinguished road
Default

or more simply


Code:
player_score++;
I when its only incrementing by the number one I try to stick with the increment operator, (++) when its a larger number I will use the +=.
SynSoft is offline   Reply With Quote
Old 06-15-2010, 05:18 PM   #4 (permalink)
Cool Person
 
Join Date: Jun 2010
Location: Minnesota
Posts: 66
mitchsamuels is on a distinguished road
Send a message via Skype™ to mitchsamuels
Default

Quote:
Originally Posted by Mjsdabeast View Post
You could use this.
Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
        //called whenever someone touches screen
	UITouch *touch = [[event allTouches] anyObject];
        

        //setup an int score in .h and use it like this
        score += 1;

       //setup a label and string that the label displays
       NSString *string = [[NSString alloc] initWithFormat:@"%d", score];
       // make a label called label
       label.text = string;
       [string release];
       
}
Hope this helps


Thank you! Just one question, when I touch it, it goes up by 4, not 1. Is that part of the code that you gave me, or is it something in mine?
mitchsamuels is offline   Reply With Quote
Old 06-15-2010, 09:31 PM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 35
SynSoft is on a distinguished road
Default

did you try changing
Code:
 score += 1;
to
Code:
 score++;
SynSoft is offline   Reply With Quote
Old 06-15-2010, 11:15 PM   #6 (permalink)
Cool Person
 
Join Date: Jun 2010
Location: Minnesota
Posts: 66
mitchsamuels is on a distinguished road
Send a message via Skype™ to mitchsamuels
Default

Quote:
Originally Posted by SynSoft View Post
did you try changing
Code:
 score += 1;
to
Code:
 score++;
Yeah. I looked through all the code, nothing to do with a 4. I have also tried:
Code:
 score += 0.25;
But it had an error and said "Invalid operands to binary +"
mitchsamuels is offline   Reply With Quote
Old 06-16-2010, 08:57 PM   #7 (permalink)
Registered Member
 
Mjsdabeast's Avatar
 
Join Date: Oct 2009
Location: Illinois
Age: 16
Posts: 94
Mjsdabeast is on a distinguished road
Default

Quote:
Originally Posted by mitchsamuels View Post
Yeah. I looked through all the code, nothing to do with a 4. I have also tried:
Code:
 score += 0.25;
But it had an error and said "Invalid operands to binary +"
Hmm, I really have no idea. Sorry.
__________________


Counting Time Now on the appstore - a very addicting strategic time game!!
http://itunes.apple.com/us/app/count...377631631?mt=8
Mjsdabeast is offline   Reply With Quote
Old 06-17-2010, 10:14 AM   #8 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 57
PuchkoffDevelopment is on a distinguished road
Default

Quote:
Originally Posted by Mjsdabeast View Post
Hmm, I really have no idea. Sorry.
try this:
Code:
count=count+1
PuchkoffDevelopment is offline   Reply With Quote
Old 06-20-2010, 11:44 AM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 31
richifie is on a distinguished road
Default

Quote:
Originally Posted by mitchsamuels View Post
Yeah. I looked through all the code, nothing to do with a 4. I have also tried:
Code:
 score += 0.25;
But it had an error and said "Invalid operands to binary +"
That exact thing happened to me- I had to start my entire project again () i mean the entire thing going up by 4 not one, then a few projects after, it started going up by like 56 IT'S CRAZY
richifie is offline   Reply With Quote
Old 06-25-2010, 04:48 PM   #10 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Going up by 4 usually means you accidentally defined score as a pointer.
JasonR 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: 403
11 members and 392 guests
7twenty7, ChrisYates, djohnson, Duncan C, gmarro, hussain1982, Kirkout, Retouchable, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

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