I have added posts to various of my previous topics concerning this issue and, after a full week on this (and this ONLY), I have yet to come up with a solution.
This is the point where I do not care how or why it works, I just want it to work.
I'm almost ready to hire a think-tank team, invest in a massive storage of snacks and food supplies and pay for everyone's transport to get over and help figure out what is going on - but this comes first...
---------------------------
Too Long, Don't Read (Skip To Here)
---------------------------
This is using Cocos2d-MAC. (You most likely do not need experience with cocos2d-MAC to solve this problem)
I am trying to link the 'File > Save' panel in the Menu Bar to a class that then creates a JSON string and saves it blah blah blah...
^(I'm not sure if that is relevant or not)^
For some unknown reason, every class I try and create that has an -(IBAction)someMethod in it, the variables don't save unless they are set in the absolute 'init' method.
What I mean is this:
I have a main layer called 'Hello World Layer', where I have an instance variable of the class 'Controller' (I retain it, remember this).
I would like to initialize the Controller class like this
controller = [[Controller alloc] initWithLevelData:blocks]; //Controller is the class, controller is the variable, blocks is an NSMutableArray
Inside controller, it goes like this:
-(id)initWithBlocks:(NSMutableArray *)b{
if ( (self = [super init]) ) {
blocks = b;
[blocks retain];
number = [NSNumber numberWithInt:5];
[number retain];
number2 = 7; //number is an NSNumber, and number2 is an integer, both are instance variables
}
return self;}
This is where things don't go right.
The values get assigned, they get stored, they look perfectly fine here after all thousand breakpoints I have set, changed and extensively tested.
Now.
If I try and access these variables from inside the class in any way, shape, or form - they return nil/NULL. (0, and 0x0).
For instance, imagine I set a property:
.h
@property int someInteger;
.m
@synthesize someInteger = number2;
If I use this inside the class, e.g:
- (IBAction)doSaveAs:(id)pId {
self.someInteger ... //Value = 0, even if initialized with a value (e.g. 13)
return;}
If I do the same from outside the class:
(In Hello World Layer).m
controller.someInteger //Value will be 13
As you can hopefully see, there is something going wrong.
The only way it works is if I do this:
(HelloWorldLayer).m
controller = [[Controller alloc] init];
(Controller).m
-(id)init {
if ( (self = [super init]) ) {
number2 = 7;
}
return self;}
Literally, if you have absolutely ANY idea as to what is going on, post. You never know with these things...
I would like it also if someone could test this and see if they get the same results.
In the MainMenu.xib create or link to a button in the menubar and create a class like I have done and see if you can get it to save the data.
:D
Thanks so much guys, help is much appreciated.
EDIT:
I also tried initializing doing '-(id)init' and then passing the level data via another method ('-(void)loadLevelData:(NSArray*)a') and it didn't store them still.