0

I have a upgradeShop.ccb file that is a layer and it has buttons on it (it's a shop to buy upgrades). I have a CCScrollView in my MainScene that I am loading my ugpradeShop.ccb. Everything works fine, except the buttons. When I click a button on the scrollview, a method is called that is supposed to subtract points from the player, and add the bonuses for the upgrade, and update the points label on MainScene. The points label is just a CCLabelTTF and it tells the player how many points the player has. I also have an NSLog in the method to make sure that it is being called.

The NSLog is working fine, so the method is being called when the button is tapped/clicked. The problem is that the label on MainScene isn't changing. To try to diagnose this, I also attempted to hide a sprite that I have on MainScene, when the button is clicked. It didn't work either.

This is what I have in MainScene. This is the method called when clicking the button.

-(void)buyItem {
if (points >= 10) {
    points -= 10;
    label.string = [NSString stringWithFormat:@"%.2Lf", points];
    NSLog([NSString stringWithFormat:@"%.2Lf", points]);
    [self didLoadFromCCB];
    }
}

I should also mention that the custom class of the CCNode in the ugpradesShop.ccb layer is set to MainScene. Heres a picture

Here is the button

I'm not sure what I'm doing wrong. I've been trying to solve this for over a week now, and reading up on the developer library but I honestly can't find what I am doing wrong.

I'm very new to obj-c so please explain in easy terms. Thank you so much.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Albert K
  • 25
  • 7
  • Is "label" non-nil? Set a breakpoint and check. – CodeSmile May 21 '14 at 20:32
  • @LearnCocos2D I used ' if (dogeAmount == nil) { NSLog(@"Nil"); }' upon view loading and it outputted Nil. So it is nil. I'm not too sure on what this means I should do – Albert K May 21 '14 at 21:05
  • Sorry by dogeAmount I mean label. thats what the label name is – Albert K May 21 '14 at 21:16
  • assign it, the label variable won't magically know which label it is supposed to refer to. For instance in spritebuilder give the label a variable name "label" and have it assigned to document root. – CodeSmile May 21 '14 at 21:31
  • @LearnCocos2D I actually do have that. The label itself is under CCNode on MainScene.ccb. I actually update the label in different situations, for example there's a button in MainScene that changes the label text and that works fine. The difference between them is that in the problem I am having now, the button isn't under the CCNode in MainScene, but under CCNode in ugpradesShop.ccb which is just a layer. Then the scrollview loads that layer. The scrollview is positioned in MainScene so that it takes up the right side of the scene, and the button should update a label on the visible side. – Albert K May 21 '14 at 23:21
  • @LearnCocos2D thought I would clarify a little bit more there. But yeah I have it assigned. [Heres a picture](http://i.imgur.com/a5znRaI.jpg?1?9084) – Albert K May 21 '14 at 23:23
  • set a breakpoint in didloadfromccb to confirm the label is set correctly, if not, check the log for any messages regrding the label – CodeSmile May 21 '14 at 23:28
  • @LearnCocos2D alright I think I did this correctly. I set up a breakpoint at the line where the '-(void)didLoadFromCCB {' is. I ran the program and in the log the label isn't mentioned. It does tell me about a nil label, but that one was from an old design and I must have missed it when I was redoing the design. It also outputs something about MainScene. [Pic here](http://i.imgur.com/FkL9R2y.jpg?2?3428) – Albert K May 21 '14 at 23:34
  • expand self and look for the mainscene label ivar, see first couple paragraphs here: https://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/DebugYourApp/DebugYourApp.html – CodeSmile May 22 '14 at 06:10
  • @LearnCocos2D ok I just expanded self. [Pic here](http://i.imgur.com/fiY5iv4.jpg?2?9882) DogeAmount is the label name, I'm just using "label" in this post because it's easier to follow. I don't know why it says its nil, I have it on document root in SpriteBuilder with the same name. – Albert K May 22 '14 at 19:34
  • @LearnCocos2D Okay I just tried this. In DidLoadFromCCB I put ' stringText = @"Test"; label.string = [NSString stringWithString:stringText];' and upon loading the app it worked and set the labels text to test. Then, I put the same code under the buttons method. I ran the program, and the labels text remained as "Sample Text". So I assume it has something to do with the method. Not sure – Albert K May 22 '14 at 21:10
  • @LearnCocos2D I just created a test project and tried to change the label. This should be easier to follow since there isn't any other code, just everything I did for the scrollview. I got the same outcome. Not sure whats up. [Pic here](http://imgur.com/a/77XyJ) – Albert K May 22 '14 at 21:30

0 Answers0