 |
 |
|
 |
07-03-2009, 01:27 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 138
|
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)levelUpPress  id)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?
|
|
|
07-03-2009, 01:37 PM
|
#2 (permalink)
|
|
New Member
Join Date: Jan 2009
Posts: 7
|
Code:
level++;
levelText.text = [NSString stringWithFormat:@"%i", level];
|
|
|
07-03-2009, 01:49 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 138
|
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....
|
|
|
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
|
Quote:
Originally Posted by garyk
Code:
level++;
levelText.text = [NSString stringWithFormat:@"%i", level];
|
Quote:
Originally Posted by xiii3
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.
|
|
|
07-03-2009, 02:09 PM
|
#5 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 138
|
- (IBAction)levelUpPress  id)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.
|
|
|
07-03-2009, 08:37 PM
|
#6 (permalink)
|
|
New Member
Join Date: Jan 2009
Posts: 7
|
Quote:
Originally Posted by xiii3
- (IBAction)levelUpPress  id)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.
|
|
|
07-04-2009, 02:11 AM
|
#7 (permalink)
|
|
iPhone Developer
Join Date: May 2009
Location: Singapore
Posts: 325
|
I do something like
in my header file.
In viewDidLoad or some other initialization method you have to state the value of level...
then the IBAction would work.
means add 1 to the level integer. It's the same as level += 1;
Hope hat helps.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 356 |
| 27 members and 329 guests |
| bachonk!, bandley, bensj, bouche, BrianSlick, carendt242, davidneal, Desdichado, elite, gomugroup, Hololont, itsugawakun, jamison, JasonR, JJBigThoughts, kanso, kieran12, Lebowski, LemonMeringue, lepetitapps, lupu1001, preiss, redmouse, RobotWoods, RyanW, smasher |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,320
Threads: 39,118
Posts: 171,515
Top Poster: smasher (2,576)
|
| Welcome to our newest member, xX Holllish Xx |
|