Joseph Posted March 8, 2014 Share Posted March 8, 2014 (edited) public enum Direction { SOUTH(0), SOUTH_WEST(256), WEST(512), NORTH_WEST(768), NORTH(1024), NORTH_EAST(1280), EAST(1536), SOUTH_EAST(1792); private int index; Direction(int index) { this.index = index; } public static String toString(int index) { for (Direction d: values()) { if (index == d.index) return d.name().replace("_", " ").toLowerCase(); } return null; } public static String toString(Direction d) { return d.name().replace("_", " ").toLowerCase(); } } You simply have to use my players "getRotation()" example: log("" +Direction.toString(myPlayer().getRotation())); pictures example: it wont let me add picture http://puu.sh/7nqGB http://puu.sh/7nqHw http://puu.sh/7nqI6 Edited March 8, 2014 by josedpay Link to comment Share on other sites More sharing options...
Swizzbeat Posted March 8, 2014 Share Posted March 8, 2014 I would overload the toString and have it take a direction enum as well. Link to comment Share on other sites More sharing options...
Joseph Posted March 8, 2014 Author Share Posted March 8, 2014 (edited) I would overload the toString and have it take a direction enum as well. i was actually doing that now for my script. ill add it in a bit edit: added it in Edited March 8, 2014 by josedpay 1 Link to comment Share on other sites More sharing options...
NotoriousPP Posted March 9, 2014 Share Posted March 9, 2014 (edited) I'm not sure if your using the toString() correctly, I don't believe you should have a input in the constructor. Shouldn't it be something like: @Override public String toString() { final String s = super.toString().replace('_', ' '); return s.charAt(0) + s.substring(1,s.length()).toLowerCase(); } And to call toString you would simply call: log(Direction.NORTH.toString()); //Outputs: North Edited March 9, 2014 by NotoriousPP Link to comment Share on other sites More sharing options...
Joseph Posted March 9, 2014 Author Share Posted March 9, 2014 I'm not sure if your using the toString() correctly, I don't believe you should have a input in the constructor. Shouldn't it be something like: @Override public String toString() { final String s = super.toString().replace('_', ' '); return s.charAt(0) + s.substring(1,s.length()).toLowerCase(); } And to call toString you would simply call: log(Direction.NORTH.toString()); //Outputs: North if you want to be all fancy you could do that with your toString(). i was just to lazy to do that. Also, the only reason why i put an argument inside the parameter because without, you wouldnt know which direction you are facing, without using player#getRotation. That the point of having toString a static method. So when you call the enum you could use that method. With out having to choose one of the actual enum option, and since you have a argument, you could simply add in your player getRotation(). for example: instead of doing this log(Direction.NORTH_WEST.toString()); log(Direction.SOUTH.toString()); log(Direction.EAST.toString()); log(Direction.NORTH.toString()); you could do log(Direction.toString(myPlayer().getRotation())); 1 Link to comment Share on other sites More sharing options...