Results 1 to 4 of 4
  1. #1
    yuuchan is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Question Make it just A, Help me please

    Hellow,
    i'm kind a confuse, please help me

    i make 2 object (car and Home)
    when object car hit object Home set value for "Path" = A
    my code that i write just like this

    public boolean foundHome()
    {
    Actor Hm = getOneObjectAtOffset (0,0, car.class);
    if (Hm != null)
    { return true; }
    else
    { return false; }
    }

    public void Act()
    {
    if (foundHome())
    { Path =Path +"A" }
    }

    but what i got is "Path = AAAAAAAAAAA"

    because image for Home is quite Big compare to image for Car
    so the foundHome() condition is "True" repeatedly and make my "Path" became "AAAAAAAA"

    what i must do, so i can get Just "A" in my "List"

    and can somebody teach me about
    thanks a lot

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    Java Code:
    Path =Path +"A"
    to

    Java Code:
    Path = "A"

  3. #3
    yuuchan is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default

    No, i want to add another String into that "Path", not just A . like if the car hit another home (witch i called B), so the Path become AB.

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    In that case, determine what the last character in the string was, and if the char that will be added is NOT the same, add the new char, otherwise, do nothing. Something like this...
    Java Code:
    String path;
    char nextChar = getLocationChar()//this method determines 
                                     //what the next character should be
    if(path.length() = 0)
         path += nextChar;
    else if(nextChar != path.charAt(path.length() - 1)
         path += nextChar;
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. want to make an array
    By doha786 in forum New To Java
    Replies: 3
    Last Post: 03-29-2009, 01:49 AM
  2. make this proje to me
    By demir12 in forum Suggestions & Feedback
    Replies: 1
    Last Post: 11-27-2008, 01:53 PM
  3. Trying to make a GUI program
    By GettinGwap in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 11:37 PM
  4. How do you make a jar file
    By alex_cunningham in forum New To Java
    Replies: 3
    Last Post: 07-15-2008, 03:56 AM
  5. i need help to make this program
    By masaka in forum New To Java
    Replies: 2
    Last Post: 03-23-2008, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •