Kalispel Posted January 20, 2016 Posted January 20, 2016 (edited) I've been making a smithing bot and I've struggled with int arrays when it comes to setting the location of the furnace. I have this in my main class: public static int[][] furnacePlace; private Area furnaceArea = new Area(furnacePlace); However, in the gui class I'm struggling to get it to take all 4 int values. if (location.equals("Port Phasmatys")) { KaliRings.furnacePlace[][] = { x, y, x ,y} } I am getting an error on the x and y values. Am I writing it wrong? or can someone explain the use of int arrays a little better to me please? Thanks. Edited January 20, 2016 by Kalispel
Vilius Posted January 20, 2016 Posted January 20, 2016 (edited) I suppose you could read this: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html but it should be: if (location.equals("Port Phasmatys")) { KaliRings.furnacePlace[][] = {x,x}, {y,y} } To get them out of there: //This will get the first x and y Position pos = new Position(KaliRings.furnace[0], KaliRings.furnace[0]); //this will get the second x and y Position pos = new Position(KaliRings.furnace[1], KaliRings.furnace[1]); Edited January 20, 2016 by Vilius 1
Token Posted January 20, 2016 Posted January 20, 2016 (edited) I've been making a smithing bot and I've struggled with int arrays when it comes to setting the location of the furnace. I have this in my main class: public static int[][] furnacePlace; private Area furnaceArea = new Area(furnacePlace); However, in the gui class I'm struggling to get it to take all 4 int values. if (location.equals("Port Phasmatys")) { KaliRings.furnacePlace[][] = { x, y, x ,y} } I am getting an error on the x and y values. Am I writing it wrong? or can someone explain the use of int arrays a little better to me please? Thanks. Well... I guess you got an error in the second part of the code. But anyway in order to construct an Area you need the southwest corner and northeast corner x and y coordinates. I don't really understand why you need to use matrices when you need 2 positions. The most logical thing to do is get the furnace Position (as a 3D vector meaning x, y and z) and then you can construct an Area relative to that Position (if you really want an Area). public static Position furnacePosition = new Position(a, b, c); // you get a, b, c ingame public static Area getFurnaceArea() { x = furnacePosition.getX(); y = furnacePosition.getY(); // define a set of rules to create a custom rectangular area // I assume in this case that the furnace is on the eastern wall of a room // which I believe it is so in Port Phasmantys Area furnaceArea = new Area(x - 6, y - 2, x, y + 2); // so this Area is supposed to be 6x4 (6 squares in front of furnace including the furnace // and 2 on each side) return furnaceArea; } You don't need int arrays. Edited January 20, 2016 by Token
Joseph Posted January 20, 2016 Posted January 20, 2016 (edited) new Area(0,0,0,0).setPlane(0) Op btw you are trying to make a 2d array that's why your messing up Example got from link above String[][] names = { {"Mr. ", "Mrs. ", "Ms. "}, {"Smith", "Jones"} }; // Mr. Smith System.out.println(names[0][0] + names[1][0]); // Ms. Jones System.out.println(names[0][2] + names[1][1]); Edited January 20, 2016 by Joseph 1
Zappster Posted January 20, 2016 Posted January 20, 2016 if (location.equals("Port Phasmatys")) { KaliRings.furnacePlace[][] = { x, y, x ,y} } This is a 1D array, not a 2D. 2D would look like: if (location.equals("Port Phasmatys")){ KaliRings.furnacePlace[][] = {x,y},{x,y} } 1
Kalispel Posted January 20, 2016 Author Posted January 20, 2016 I suppose you could read this: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html but it should be: if (location.equals("Port Phasmatys")) { KaliRings.furnacePlace[][] = {x,x}, {y,y} } To get them out of there: //This will get the first x and y Position pos = new Position(KaliRings.furnace[0], KaliRings.furnace[0]); //this will get the second x and y Position pos = new Position(KaliRings.furnace[1], KaliRings.furnace[1]); Thanks