2

I am working on my first iPhone game and am wondering how to return a value from a function when this first function calls a second function? The functions returns bools.

Here is some sample code:

// This is sample calls to inrect functions:
[menuButton inrect:point] // Calls the first function which calls second function
[menuButton inrect:point:0.5] // No problem because calls the second function directly

Here are functions:

- (BOOL) inrect:(CGPoint)_point{
    [self inrect:_point:0]; //call second function with offset of 0
    return 0; //How do I return the value of the above call?
}

- (BOOL) inrect:(CGPoint)_point:(float)offset{
    if (_point > 0 && offset > 1) {
        return YES;
    }
    if (_point < 0 && offset < 1) {
        return YES;
    }   
    return NO;
}

There is no problem when I call the second function directly, but when calling the first function, which in turns calls the second function, how do I properly return the value of the second function back to the first function so it can return it to where it was called from.

Thanks

2 Answers 2

4

I'm not sure I'm getting you. Just return it:

return [self inrect:_point:0];
1
  • Yes this is what I needed! Very obvious now. Thanks
    – jsherk
    Feb 23, 2012 at 17:57
2

I am not sure to understand your problem, but maybe you want to do this:

- (BOOL) inrect:(CGPoint)_point
    {
        BOOL aBool = [self inrect:_point:0]; //put the return in a BOOL and do what you want with it
        NSLog(@"Not expecting to this, but I do!");
        return 0;
    }

EDIT

- (BOOL) inrect:(CGPoint)_point
    {
        return [self inrect:_point:0];
    }
1
  • I guess you mean return aBool;
    – sch
    Feb 23, 2012 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.