payton9812 Posted February 28, 2018 Share Posted February 28, 2018 I can't figure out why this is always returning false... private boolean atBankPosition() { Position pos = new Position(3185, 3444, 0); if (myPosition() == pos) return true; else return false; } Any help? Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted February 28, 2018 Share Posted February 28, 2018 This is actually the wrong section for this. You can't compare 2 objects using ==, you should use .equals(). private boolean atBankPosition() { Position pos = new Position(3185, 3444, 0); return pos.equals(myPosition()); } 1 Quote Link to comment Share on other sites More sharing options...
Butters Posted February 28, 2018 Share Posted February 28, 2018 (edited) 3 minutes ago, payton9812 said: I can't figure out why this is always returning false... private boolean atBankPosition() { Position pos = new Position(3185, 3444, 0); if (myPosition()equals(pos)) return true; else return false; } Any help? Use equals() and not ==, that is if (myPosition()equals(pos)) return true; else return false; This is because == checks if two objects ARE THE SAME IN MEMORY, which they are not. equals(), if coded properly, checks the values of the objects and that is what you need Edited February 28, 2018 by Butters 1 Quote Link to comment Share on other sites More sharing options...
payton9812 Posted February 28, 2018 Author Share Posted February 28, 2018 I understand now, I can use " pos.equals(myPosition()); " as a bool, which is exactly what I needed. Thank you. Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted February 28, 2018 Share Posted February 28, 2018 Maybe it’s good to go for a basic java course, this should be basic knowledge . 1 Quote Link to comment Share on other sites More sharing options...