only one error left! Please help...

Kingbry
Unregistered
 
Post: #1
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??
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #3
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.
Quote this message in a reply
Kingbry
Unregistered
 
Post: #4
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? Huh Lol, I know I sound pathetic now... Grin
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Code:
[NSValue valueWithPoint:aPoint]

and on the other side

Code:
[aValue pointValue]

from memory...
Quote this message in a reply
Kingbry
Unregistered
 
Post: #6
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. Huh
Quote this message in a reply
Member
Posts: 254
Joined: 2005.10
Post: #7
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:
Code:
- (void) setPosition: (NSValue) pos
{
position_ = [pos pointValue];
}

Or you could unwrap the point before passing it into setPosition.
Quote this message in a reply
Kingbry
Unregistered
 
Post: #8
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...

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]];
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #9
Code:
...[NSValue valueWithPoint: NSPointFromString
     (kCapturedPositionKey)], kCapturedPositionKey ...

Are you sure about that bit? The same string is both the key and the point?
Quote this message in a reply
Kingbry
Unregistered
 
Post: #10
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!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
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...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Left mouse button causes moueup event despite button still being pressed. QuestingCordiial 28 11,441 Jun 21, 2008 03:18 PM
Last Post: AnotherJake