Results 1 to 7 of 7
  1. #1


    Member Since
    Aug 30, 2011
    Posts
    4
    Button Looping and me!
    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??!?!"];
            }
    }

  2. #2


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    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, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; 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 Linux; Apple TV (1080p version)

  3. #3


    Member Since
    Aug 30, 2011
    Posts
    4
    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.

  4. #4


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    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, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; 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 Linux; Apple TV (1080p version)

  5. #5


    Member Since
    Aug 30, 2011
    Posts
    4
    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.

  6. #6


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    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, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; 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 Linux; Apple TV (1080p version)

  7. #7


    Member Since
    Aug 30, 2011
    Posts
    4
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Looping AppleScript
    By Nosrettap in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 08-02-2011, 06:54 AM
  2. Macbook Looping
    By grodrigz in forum Apple Notebooks
    Replies: 0
    Last Post: 06-12-2009, 03:04 AM
  3. Looping Finder Crash
    By simbey1982 in forum OS X - Operating System
    Replies: 16
    Last Post: 02-28-2009, 02:48 AM
  4. Looping Restart Screen
    By lemondime in forum OS X - Operating System
    Replies: 0
    Last Post: 01-22-2009, 12:07 AM
  5. Keynote looping problems...
    By georgewarburton in forum OS X - Operating System
    Replies: 0
    Last Post: 11-27-2008, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •