Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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 07-03-2009, 01:27 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 138
Default Level Up / Down Buttons

Ive been having some trouble creating a set of level skip up/down buttons.

So far all ive got is two buttons and a label with 'Level @%' in it

- (IBAction)levelUpPressid)sender

{
if (levelText = '1')
[levelText = 2];
if (.... and so on
}

works in terms of changing the number in the label from 1 to 2 but a second press doesnt change it from 2 to 3... is there a simpler way or should i just crack on getting this to count upwards using ifs?
xiii3 is offline   Reply With Quote
Old 07-03-2009, 01:37 PM   #2 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 7
Default

Code:
level++;
levelText.text = [NSString stringWithFormat:@"%i", level];
garyk is offline   Reply With Quote
Old 07-03-2009, 01:49 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 138
Default

so....

- (IBAction)levelUpPress id )sender

{
level++;
levelText.text = [NSString stringWithFormat:@"%i"];

}
doesnt build...

what is the level++ part? ive never come across it... \

basically right now all i need is to have a button that adds 1 to the value of a label and i was thinking of using the labels value to set the rest of the variables up....
xiii3 is offline   Reply With Quote
Old 07-03-2009, 01:56 PM   #4 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: ¿La Islas Hermosas?
Posts: 1,429
Default

Quote:
Originally Posted by garyk View Post
Code:
level++;
levelText.text = [NSString stringWithFormat:@"%i", level];
Quote:
Originally Posted by xiii3 View Post
so....

- (IBAction)levelUpPress id )sender

{
level++;
levelText.text = [NSString stringWithFormat:@"%i"];

}
doesnt build...

what is the level++ part? ive never come across it... \

basically right now all i need is to have a button that adds 1 to the value of a label and i was thinking of using the labels value to set the rest of the variables up....
Compare the code originally posted with what you've currently got. Also, if you don't know what "++" does, you should locate a C language reference manual and keep it handy.
__________________
piña para la niña interactive
Kalimba is offline   Reply With Quote
Old 07-03-2009, 02:09 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 138
Default

- (IBAction)levelUpPressid)sender

{
level++;
levelText.text = [NSString stringWithFormat:@"%i", level];

}

ok typo... but what do i do with the level bit...? the label will follow the number of my level.... but where do i define it? at the minute the 'level' is an undeclared function and i have no idea where to put it... sorry this part of programming is new to me completely.

Last edited by xiii3; 07-03-2009 at 02:17 PM.
xiii3 is offline   Reply With Quote
Old 07-03-2009, 08:37 PM   #6 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 7
Default

Quote:
Originally Posted by xiii3 View Post
- (IBAction)levelUpPressid)sender

{
level++;
levelText.text = [NSString stringWithFormat:@"%i", level];

}

ok typo... but what do i do with the level bit...? the label will follow the number of my level.... but where do i define it? at the minute the 'level' is an undeclared function and i have no idea where to put it... sorry this part of programming is new to me completely.
level is an NSInteger. I assumed you declared this in your header file.
garyk is offline   Reply With Quote
Old 07-04-2009, 02:11 AM   #7 (permalink)
iPhone Developer
 
kohjingyu's Avatar
 
Join Date: May 2009
Location: Singapore
Posts: 325
Default

I do something like
Code:
int level;
in my header file.

In viewDidLoad or some other initialization method you have to state the value of level...

Code:
level = 1;
then the IBAction would work.

Code:
level ++;
means add 1 to the level integer. It's the same as level += 1;

Hope hat helps.
kohjingyu 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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,320
Threads: 39,118
Posts: 171,515
Top Poster: smasher (2,576)
Welcome to our newest member, xX Holllish Xx
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:55 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0