Question [Probably Simple Answer]

Discussion in 'iOS Development' started by JoshuaCaputo, Jun 2, 2009.

  1. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    How can i do something like:

    Code:
    NSString *currentPlayer = @"player1";
    [currentPlayer].center = CGPointMake(x,y);
    
    I hope that makes sense to everyone what im trying to accomplish.

    EDIT:
    I want the value, I wasn't clear:
    Code:
    [currentPlayer value].center = CGPointMake(x, y);
    
    REEDIT:

    I want to put the value of the string in place of the name!, let me explain again.

    say heres the players: player1, player2, player3, player4.
    and I have a string defining which player whos turn it is: NSString *curPlayer = @"player1";

    and I want to switch:
    Code:
    player1.center = CGPointMake(x,y);
    
    to
    Code:
    [the value of the curPlayer string (which is player1)].center = CGPointMake(x, y);
    
  2. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    NSString is not an UI object, so you can't "draw" it just like that. You have to use a label, or a TextView.
  3. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    I want the value, I wasn't clear:

    [currentPlayer value].center = CGPointMake(x, y);
  4. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    Code:
    NSString *text = @"hello";
    [text drawAtPoint:CGPointMake(0,0)];
    
    Now what was that again?
  5. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    I want to put the value of the string in place of the name!, let me explain again.

    say heres the players: player1, player2, player3, player4.
    and I have a string defining which player whos turn it is: NSString *curPlayer = @"player1";

    and I want to switch:

    player1.center = CGPointMake(x,y);

    to

    [the value of the curPlayer string (which is player1)].center = CGPointMake(x, y);
  6. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    It doesn't work like that.
  7. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    is that possible in anyway? or do i have to do if statements for everything.

    if (player = 1){ ect

    I thought i could get it in one line

    because I know u can do things like [touch view].center and stuff like that.
  8. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    The string has no idea where it is on the screen, you just told it to draw somewhere.

    Just use another UI element like a label to do it.
  9. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    f***!, Im not trying to draw the string.

    Im trying to say in english.

    current player is player 1

    the center of the [current player] is (x,y)
  10. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    I don't get it.

Share This Page