I am using sprite builder and Xcode.
Does anyone see where I am going wrong with my code block "whereToNext" property? Im trying to use it to navigate between scenes but for some reason it isn't going into the initialization code in -(void)patterns even though it is going into the patterns method. Since it never goes into the whereToNext=^{} code, when i call it in the next() method nothing happens. (The next method is called via a code connection to a button in sprite builder.)
As a second question concerning CCTextField: I placed two CCTextField node in my TrialCustomization.cbb (which has the ExperimentSelection custom class code connection) on sprite builder and then created two doc root var code connection "_blocks" and "_trials" then created a variable in the corresponding class with the same name CCTextField *_blocks; and the same for _trials but when i give that text field input it doesn't save it into the variables i saved them into in their corresponding methods.
#import "CCNode.h"
@interface ExperimentSelection : CCNode
@property (nonatomic, copy) void(^whereToNext)(void);
@property CCTextField* _trials;
@property CCTextField* _blocks;
extern int trials;
extern int blocks;
-(void)patterns;
-(void)setTrialandBlock;
@end
@implementation ExperimentSelection
@synthesize whereToNext;
@synthesize _blocks;
@synthesize _trials;
-(void)patterns{
whereToNext=^{
CCScene *patternsSelection = [CCBReader loadAsScene:@"PatternsSelection"];
[[CCDirector sharedDirector] replaceScene:patternsSelection];
NSLog(@"Why is this code not being executed??");
};
NSLog(@"whereToNext: %@", whereToNext);
[self setTrialandBlock];
}
-(void)_trials:(CCTextField*)trialsNum{
trials=[trialsNum.string intValue];
}
-(void)_blocks:(CCTextField*)blocksNum{
blocks=[blocksNum.string intValue];
}
-(void)setTrialandBlock{
CCScene *customizeExperiment = [CCBReader loadAsScene:@"TrialCustomization"];
[[CCDirector sharedDirector] replaceScene:customizeExperiment];
NSLog(@"blocks: %i, trials: %i",blocks, trials);
}
-(void)next{
NSLog(@"wherearewegoingnext: %@, blocks: %i, trials: %i",whereToNext, blocks, trials);
whereToNext();
}
@end
Are you sure what
-(void)patterns
was called?If YES, try change
void(^whereToNext)(void);
to
@property(nonatomic, copy) void(^whereToNext)(void);
UPD
I think there is no problem with creation of block or with execution of the block. I think there is some logic problem in the code. May be exist some parent or child class that overload "patterns" method. You can add a break point to property whereToNext and view then this property is changed.