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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 06-23-2009, 02:37 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 31
Default Use string to call a function

I'm creating a game and I need to call an action. My problem is that I need the function being called to change according to the level the user is one. I have the whole thing basically worked out where the game finds what level the user is one and then adds one to it but since the game has 50 levels so far using if statements is kind of stupid. So I have been experimenting with makeing a string that has an integer value that changes but I can't get my application to recognize that the string is a function and nothing happens.

Thus what i have and have tried many variations of this idea:
Code:
int points = [num.text intValue]; /*find the level*/
points = points +1

function = [NSString stringwithFormat:@"Q%iR:(id)sender", points];

[self function];
pete42 is offline   Reply With Quote
Old 06-23-2009, 03:10 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

You can performSelector to call a method on any object, and you can even pass in a parameter object- like so:

Code:
	SEL selector = NSSelectorFromString(@"myMethod:"]);
	[self performSelector: selector withObject: myObject];
If you have no parameters, it's just
Code:
	SEL selector = NSSelectorFromString(@"myMethod"]);
	[self performSelector: selector];
__________________

Free Games!
smasher is offline   Reply With Quote
Old 06-23-2009, 04:01 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 31
Default

OMG thank you so much it works perfectly, thanks to you my game engine is finally finished.
pete42 is offline   Reply With Quote
Reply

Bookmarks

Tags
action, call, function, game, string

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: 266
14 members and 252 guests
2WeeksToGo, AdamL, ADY, BrianSlick, Dani77, Dattee, headkaze, mer10, prchn4christ, smithdale87, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,747
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

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