HomeForumsGeneral DiscussionIn Monster Checker how to save state??

This topic has 2 voices, contains 3 replies, and was last updated by  Nat Weiss 97 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
Author Posts
Author Posts
February 3, 2012 at 4:58 pm #2263

Banchain

I have buy your book and I want to know something about save state in Monster Checker.

If I want to save state after I terminate the Monster Checker App.When I re-open the game, how could the state will exist in the latest position,not at the starting point.

Of course, the piece is kept in the NSMutableArray so the question that I ask may be ,in other words, How to save a NSMutalbeArray that contain a class.

Thanks by the way

February 7, 2012 at 10:58 pm #2266

Nat Weiss

Check out the Quexlor project and how it saves state with its Settings object. To store an array, you just use NSCoder’s `encodeObject` and `decodeObjectForKey`.

February 8, 2012 at 7:58 am #2267

Banchain

I can’t do it.

If I save an integer,float,bool etc. it is OK

but when I save an arrayObject it have an error like this

//////////////////////////////// ##################################### ////////////////////////////////////

2012-02-08 14:46:00.897 A – Math[602:10a03] -[zeros encodeWithCoder:]: unrecognized selector sent to instance 0xf75cfc0
2012-02-08 14:46:00.902 A – Math[602:10a03] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[zeros encodeWithCoder:]: unrecognized selector sent to instance 0xf75cfc0′
*** First throw call stack:

//////////////////////////////// ##################################### ////////////////////////////////////

while my class name zeros

(If I did not save to save path (Save to file) it will ok to save
,but when I save to file it have an error

in other word
when use [NSKeyedArchiver archiveRootObject:dataObject toFile:savePath];

if savePath = nill; –> it can save
if savePath = @”savefile0.sav”; –> Have Error so that I can’t use your LoadState Function too

)

February 11, 2012 at 7:51 pm #2271

Nat Weiss

You don’t want to do: [zeros encodeWithCoder:]

You want to do this:

-(void) encodeWithCoder:(NSCoder*)coder
{
// encode an object
[coder encodeObject:zeroes forKey:@"zeroes"];

// encode an integer
[coder encodeInt:someInt forKey:@"someInt"];

// …
}

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.