only one error left! Please help...
Okay, so I've advanced a bit on my own, and now I am down to one error: "incompatible type for argument 1 of setPosition:"
Here is the essential pieces of code...
return [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:
score_], kCapturedScoreKey, [NSNumber numberWithInt: health_],
kCapturedHealthKey, keys_, kCapturedKeysKey, [NSNumber numberWithInt:
playerIndex_], kPlayerIndexKey, NSPointFromString (kCapturedPositionKey),
kCapturedPositionKey, nil];
then later, in another function, the source of the error:
[self setPosition: [captureDictionary objectForKey: kCapturedPositionKey]];
and then setPosition is this simple line of text.
- (void) setPosition: (NSPoint) pos
{
position_ = pos;
}
So where am I going wrong??
Here is the essential pieces of code...
return [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:
score_], kCapturedScoreKey, [NSNumber numberWithInt: health_],
kCapturedHealthKey, keys_, kCapturedKeysKey, [NSNumber numberWithInt:
playerIndex_], kPlayerIndexKey, NSPointFromString (kCapturedPositionKey),
kCapturedPositionKey, nil];
then later, in another function, the source of the error:
[self setPosition: [captureDictionary objectForKey: kCapturedPositionKey]];
and then setPosition is this simple line of text.
- (void) setPosition: (NSPoint) pos
{
position_ = pos;
}
So where am I going wrong??
You can't put an NSPoint in a dictionary (or take it out again) because it's a struct, not an object. You need to wrap it in an NSValue first.
Let me just say that your post was exemplary: well put, to the point and clear, with code and highlighted parts. Thanks for your effort.
OneSadCookie Wrote:You can't put an NSPoint in a dictionary (or take it out again) because it's a struct, not an object. You need to wrap it in an NSValue first.
Thank you... so how do I do that?
Lol, I know I sound pathetic now...
Code:
[NSValue valueWithPoint:aPoint]and on the other side
Code:
[aValue pointValue]from memory...
I'm still confused how to actually call pointValue.... I can do it in the setPosition call, right? Also, from my internet digging around, it seems that pointValue returns only the Y axis.
In order to insert the point value into the dictionary, you have to wrap it in the NSValue with the first line of code OSC showed you. Then when you want to take the point back out of the dictionary you need to remove the wrapper. So you get:
Or you could unwrap the point before passing it into setPosition.
Code:
- (void) setPosition: (NSValue) pos
{
position_ = [pos pointValue];
}Or you could unwrap the point before passing it into setPosition.
So here is what I have now... The gate, instead of keeping the location from the previous map, warps the player to position (0,0) on the new map.
building the NSDictionary...
and then unbuilding the Dictionary...
building the NSDictionary...
Code:
return [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:
score_], kCapturedScoreKey, [NSNumber numberWithInt: health_],
kCapturedHealthKey, keys_, kCapturedKeysKey, [NSNumber numberWithInt:
playerIndex_], kPlayerIndexKey, [NSValue valueWithPoint: NSPointFromString
(kCapturedPositionKey)], kCapturedPositionKey, nil];and then unbuilding the Dictionary...
Code:
[self setPosition: [[captureDictionary objectForKey: kCapturedPositionKey] pointValue]];Code:
...[NSValue valueWithPoint: NSPointFromString
(kCapturedPositionKey)], kCapturedPositionKey ...Are you sure about that bit? The same string is both the key and the point?
Thank-you, that was the problem. These NSDictionaries are complex little things.
You guys really are very helpful. I never could have done it without your help everyone!
You guys really are very helpful. I never could have done it without your help everyone!
If you lay out the dictionaryWithObjectsAndKeys: call so it has one object and one key on each line it will be much easier to understand...
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Left mouse button causes moueup event despite button still being pressed. | QuestingCordiial | 28 | 10,160 |
Jun 21, 2008 03:18 PM Last Post: AnotherJake |
|

