Cockiezi Posted January 21, 2015 Share Posted January 21, 2015 (edited) Hi I'm new at this. idk how to say this, I'm trying to store multiple areas in an array. like placeA[3] <-- My array. placeA[0] = topLeftX, topLeftY, botRightX, botRightY placeA[1] = same as above but different values. placeA[2] = same as aboev but different values. http://i.imgur.com/Xz9iuHO.jpg I want to make this so I can check if my character is inside any of them. Edited January 22, 2015 by Cockiezi Link to comment Share on other sites More sharing options...
Joseph Posted January 21, 2015 Share Posted January 21, 2015 for this you should defiantly use an enum. All you have to do is create the constructor of the enum with an area. Then you can loop throught the array using EnumName.values(); Link to comment Share on other sites More sharing options...
Cockiezi Posted January 22, 2015 Author Share Posted January 22, 2015 How would that work.. I'm confused Link to comment Share on other sites More sharing options...
Joseph Posted January 22, 2015 Share Posted January 22, 2015 (edited) How would that work.. I'm confused give me a sec i got you edit: public enum Location { //your pre-definding the value of whatever you need. AREA_ONE(new Area(3092, 3246, 3095, 3240)), AREA_TWO (new Area(3215, 9623, 3219, 9620)), AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)), ; //these are the private fields you pre-definded private Area area; //constructor add what values you need to pre-define private Location(Area area){ this.area = area; } //these are simple getter methods. //setter method arent allowed because the values are pre-fined so they are basically static. public Area getArea(){ return this.area; } } example of an enum. You pre-define the value and use them like so Location.AREA_ONE give you the variable from location and then your allowes to use the getter methods. Location.values() give your an array of all the variables in the enum You can also use an enum as a type. For oop ideas Edited January 22, 2015 by josedpay Link to comment Share on other sites More sharing options...
Cockiezi Posted January 22, 2015 Author Share Posted January 22, 2015 (edited) lemme try that I'm getting an error with this: if (placeA.values().contains(myPlayer().getPosition())){ } Edited January 22, 2015 by Cockiezi Link to comment Share on other sites More sharing options...
Mysteryy Posted January 22, 2015 Share Posted January 22, 2015 Hi I'm new at this. idk how to say this, I'm trying to store multiple areas in an array. like placeA[3] <-- My array. placeA[0] = topLeftX, topLeftY, botRightX, botRightY placeA[1] = same as above but different values. placeA[2] = same as aboev but different values. http://i.imgur.com/Xz9iuHO.jpg I want to make this so I can check if my character is inside any of them. See this post I made, it should help you out. It basically has everything you are looking for, you can just change the area implementation. http://osbot.org/forum/topic/64420-banking-enum-with-areas-and-methods/#entry707698 Link to comment Share on other sites More sharing options...
Joseph Posted January 22, 2015 Share Posted January 22, 2015 See this post I made, it should help you out. It basically has everything you are looking for, you can just change the area implementation. http://osbot.org/forum/topic/64420-banking-enum-with-areas-and-methods/#entry707698 thats where i took my explain from lol :P Link to comment Share on other sites More sharing options...
Novak Posted January 22, 2015 Share Posted January 22, 2015 give me a sec i got you edit: public enum Location { //your pre-definding the value of whatever you need. AREA_ONE(new Area(3092, 3246, 3095, 3240)), AREA_TWO (new Area(3215, 9623, 3219, 9620)), AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)), ; //these are the private fields you pre-definded private Area area; //constructor add what values you need to pre-define private Location(Area area){ this.area = area; } //these are simple getter methods. //setter method arent allowed because the values are pre-fined so they are basically static. public Area getArea(){ return this.area; } } example of an enum. You pre-define the value and use them like so Location.AREA_ONE give you the variable from location and then your allowes to use the getter methods. Location.values() give your an array of all the variables in the enum You can also use an enum as a type. For oop ideas 1 Link to comment Share on other sites More sharing options...
Cockiezi Posted January 22, 2015 Author Share Posted January 22, 2015 Soo would I be doing it the wrong way if I did this instead: if (placeA_A1.contains(myPlayer().getPosition()) || (placeA_A2.contains(myPlayer().getPosition()))){ return State.placeA; } Ofc I'd still need to define the areas, but it gets the job done. One problem with this is that when there's many areas in placeX, the if statement would get veeeeery long. Link to comment Share on other sites More sharing options...
Joseph Posted January 22, 2015 Share Posted January 22, 2015 He has to learn some where. Link to comment Share on other sites More sharing options...
Alek Posted January 22, 2015 Share Posted January 22, 2015 Or he could use the Banks class to use the exact polygons of the banks instead of arbitrary rectangles ;) 1 Link to comment Share on other sites More sharing options...
Khaleesi Posted January 22, 2015 Share Posted January 22, 2015 Use PositionPolygon? Link to comment Share on other sites More sharing options...
Isolate Posted January 22, 2015 Share Posted January 22, 2015 Well i don't see the point in coding more than you have to... Sure this: public enum Location { //your pre-definding the value of whatever you need. AREA_ONE(new Area(3092, 3246, 3095, 3240)), AREA_TWO (new Area(3215, 9623, 3219, 9620)), AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)), ; //these are the private fields you pre-definded private Area area; //constructor add what values you need to pre-define private Location(Area area){ this.area = area; } //these are simple getter methods. //setter method arent allowed because the values are pre-fined so they are basically static. public Area getArea(){ return this.area; } } Looks great and all but why when Area AREA_ONE = new Area(3092, 3246, 3095, 3240); Area AREA_TWO = new Area(3215, 9623, 3219, 9620); Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216); Would do the same thing or even storing it it a lil nooby class like public class Areas { static Area AREA_ONE = new Area(3092, 3246, 3095, 3240); static Area AREA_TWO = new Area(3215, 9623, 3219, 9620); static Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216); } would do the same thing It might just be me being super lazy but i see no point in over complicating the situation Someone plz enlighten me. Link to comment Share on other sites More sharing options...
Cockiezi Posted January 22, 2015 Author Share Posted January 22, 2015 (edited) Btw what I'm trying to accomplish has nothing to do with banking. It's for an agility script. Also now that I'm here, did the new java update break eclipse for any of you? Edit: https://www.eclipse.org/forums/index.php/t/956989/ I'm not the only one Edited January 22, 2015 by Cockiezi Link to comment Share on other sites More sharing options...
Joseph Posted January 22, 2015 Share Posted January 22, 2015 Use PositionPolygon? we were never explained how to use it. Or he could use the Banks class to use the exact polygons of the banks instead of arbitrary rectangles he never say anything about banks. I use that enum above as an example. Well i don't see the point in coding more than you have to... Sure this: public enum Location { //your pre-definding the value of whatever you need. AREA_ONE(new Area(3092, 3246, 3095, 3240)), AREA_TWO (new Area(3215, 9623, 3219, 9620)), AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)), ; //these are the private fields you pre-definded private Area area; //constructor add what values you need to pre-define private Location(Area area){ this.area = area; } //these are simple getter methods. //setter method arent allowed because the values are pre-fined so they are basically static. public Area getArea(){ return this.area; } } Looks great and all but why when Area AREA_ONE = new Area(3092, 3246, 3095, 3240); Area AREA_TWO = new Area(3215, 9623, 3219, 9620); Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216); Would do the same thing or even storing it it a lil nooby class like public class Areas { static Area AREA_ONE = new Area(3092, 3246, 3095, 3240); static Area AREA_TWO = new Area(3215, 9623, 3219, 9620); static Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216); } would do the same thing It might just be me being super lazy but i see no point in over complicating the situation Someone plz enlighten me. with an enum you can loop through the variables rather than having a nested if statement. Link to comment Share on other sites More sharing options...