New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
iOS Development Discussion on developing apps for the iOS platform.

Button Looping and me!


Post Reply New Thread Subscribe

 
Thread Tools
anonix

 
Member Since: Aug 30, 2011
Posts: 4
anonix is on a distinguished road

anonix is offline
Hey guys how is everyone today? I just had a couple questions and wondering if anyone could help.

I been trying to write a Xcode 4 cocoa app that is a guessing game. I was able to complete the game in the console, but now that I am trying to link it to a UI I'm finding it not so easy.

This is the basic Idea, i know its off. I had it working at one point but every time i hit the button it generated a new random number and i can't figure out how to do it outside the button, and how to add 5 tries before calling game over.

Code:
@implementation LoopingAppDelegate

-(void)setStuff:(id)sender{
    NSInteger g = [input];
    NSInteger y;
    NSInteger x = rand() % 100;
    
   
    
}

- (IBAction)run:(id)sender
{
     [y setIntValue:[x intValue]];
    if([g] intValue] == x){
        [results setStringValue:@"YOU ARE CORRECT SIR!!!"];
        return;}
    else if(guess.intValue < y.intValue){
        [results setStringValue:@"Higher \nGuess again!"];}
    else if(guess.intValue > y.intValue){
        [results setStringValue:@"Lower \nGuess again!"];}
    else {
        [results setStringValue:@"What the **** did you type??!?!"];
        }
}
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,092
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
Hi, welcome to the forums.

First, you may want to use code tags to make your code easier to read (maintains indenting and doesn't implement smileys)

Second - you have the line: [self release]; - I can't see ANY reason why you would want to do this unless you want to create a crash. If you need to show a different view (or return to a previous view), there are specific ways of handling that.

Third - I'm not sure what you mean by having it generate the random number outside of the button - at what time would you want the random number to be generated? In terms of guesses, you need to keep a counter to see how many guesses were entered and when that counter reached your max guess threshold that it would throw a you lost message.

Fourth - I'm not sure if this program is ultimately meant for OSX or an iOS device. You mentioned Cocoa, which would imply you intend this for OSX (iOS is Cocoa Touch) - if this is for OSX, you may want to ask that this thread get moved to the OSX development thread

My Macs: Late 2013 rMBP w/ 750m; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
anonix

 
Member Since: Aug 30, 2011
Posts: 4
anonix is on a distinguished road

anonix is offline
1. sorry about the tags thing

2. I thought the release meant it would kick me out of those brackets.

3. When i had the random number generated in the button, it would create a new number every time i clicked the button. So I'm not sure where to put it.

4. I would like this to be for the IOS, I felt that making it in OSX was a little easier and quicker to test.

Im still trying to learn everything and understand objective c, Any help would be appreciated. I figured if someone understood my goal maybe they can show me the right way to be doing it.
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,092
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
No worries on the tag thing - a lot of people don't realize their importance at first (that includes me ) - just makes the code sooo much easier to read - at least on this forum - there's another one I go to where it changes the color of the text making it really hard to read .

On the release issue,

[blablabla release];

will signify that you want to release the memory and reduce the retain count, if the retain count on an object reaches 0, it will be dealloc'd at which time it will really be gone and anything referencing it will be referencing bad memory and thro a bad exc error or something similar.

When would you like the random number generated? On first entry and after 5 attempts?

My Macs: Late 2013 rMBP w/ 750m; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
anonix

 
Member Since: Aug 30, 2011
Posts: 4
anonix is on a distinguished road

anonix is offline
Thanks a ton for the help, and working with me.

For the randomly generated number I would like to generate 1 number per 5 attempts and generate a new number if someone chooses to try again.

I have been taking a lot of tutorials and reading a couple Xcode books, the hardest part to learning is that most of the information was built for older versions of Xcode. I think thats why I was using the release. I noticed in Xcode 4 I can enable garbage clean up, which i think is what you explained.

But now as I learn more I realize I need a lot more code to get this right.

Ill be working on this for a couple days, I would love any input or ideas, or ways to do it easier. Im starting from the beginning so, this may take a while.
QUOTE Thanks
Nethfel

 
Member Since: Feb 25, 2009
Posts: 2,092
Nethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of lightNethfel is a glorious beacon of light
Mac Specs: Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10

Nethfel is offline
Well, in terms of garbage collection, it's not really an XCode thing - and it's been available for a while, but it's ONLY for OSX apps, there is no garbage collection on iOS. Plus, what garbage collection is meant for is basically so you can be lazy about making sure you release your objects. Once the system determines that there is nothing holding onto a chunk of memory it gets released - to learn more about garbage collection, see: Loading…

Just remember, it's not available on iOS. The closest thing to garbage collection won't be available until the next iOS release.

I don't have time tonight, but I'll see if I can throw together some sample code about what you are trying to do. it won't be pretty and depending on my time available tomorrow it may be for iOS rather then OSX, but hopefully it may get you in the right direction.

My Macs: Late 2013 rMBP w/ 750m; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Debian as a server; Apple TV (1080p version)
QUOTE Thanks
anonix

 
Member Since: Aug 30, 2011
Posts: 4
anonix is on a distinguished road

anonix is offline
I appreciate everything you have done to help me understand this stuff. I been working in IOS and learning a lot more about how it all links together. I took an Objective C class and I guess it was based in OSX. I plan on doing all IOS apps in the future. I also noticed that in this version of Xcode it auto adds my releases to viewDidLoad and Dealloc. Thanks a lot! your the best.
QUOTE Thanks

Post Reply New Thread Subscribe


« Value passing problem from once class to another | Problem while doing integration »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
Forum Jump

All times are GMT -4. The time now is 03:07 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?