Jump to content

How to fill correct values for int[][]?


Recommended Posts

Posted (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 by Kalispel
Posted (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 by Vilius
  • Like 1
Posted (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 by Token
Posted (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 by Joseph
  • Like 1
Posted

 

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...