#matrixX and matrixY

1 messages · Page 1 of 1 (latest)

scenic swan
#

hi

livid hound
#

hello

verbal lantern
#

hi

livid hound
scenic swan
#

please leave the thread heisenburger

livid hound
#
public GameObject GetPosition(int x, int y)
    {
        return positions[x, y];
    }

so you wanna to somehow change x and y values of this method?

scenic swan
#

GameObject cp = controller.GetComponent<GameManager>().GetPosition(matrixX, matrixY);

#

i want to change the x and y here

livid hound
#

the question is quite unclear

scenic swan
#

how

#

i want to know how to access the matrixX and matrixY of cp

#

and change it

#

in an if

livid hound
livid hound
scenic swan
#
if (controller.GetComponent<GameManager>().GetPosition(matrixX, matrixY) == reference.GetComponent<Chessmen>().wRooks[1])
            {
                matrixX = getBoardX + 2;
                cp.idk = getBoardX + 1;
                Debug.Log(getBoardX);
            }
#

in there

livid hound
#

GameObject does not have those matrixX and matrixY values

livid hound
#

the script you are actually in now

#

in code I mean

#

ya undestood.

scenic swan
#

idk

livid hound
#

it should be smth like this

scenic swan
#

cuz like

#

matrixX is currently where the weird rook is.
matrixX = getBoardX + 2; makes the king move twice to the right (getBoardX is the original location of the king)

livid hound
#
using UnityEngine;

public class TargetController : MonoBehaviour
{
    // those are the values you do can change
    public float matrixX, matrixY;
}
scenic swan
#

i want to put the rook that is on the location of cp and move it

livid hound
scenic swan
#

wdym

livid hound
#

you need to have script for this

scenic swan
#

but if i put the GameObject that is on matrixX and matrixX and put it into cp

#

could i be able to change

#

the x and y

#

of cp

livid hound
#
using UnityEngine;

public class ChessPiece : MonoBehaviour
{
    // those values are width and height of 1 chess square respectfully
    private float xDistance, yDistance;

    // x and y range from -7 to 7 (because chess board is 8x8)
    public void Move(int x, int y)
    {
        transform.position.x += xDistance * x;
        transform.position.y += yDistance * y;
    }
}
#

that's the most simple way I guess

#

and it can deffer from what you need

scenic swan
#

SetCoords() of Chessmen.cs has x and y variables which is the xDist and yDist

unkempt meadow
#

If I'm understanding correctly, you want to update a piece's location within the GameManager.positions array?

livid hound
unkempt meadow
scenic swan
#

lemme brb for like 30 mins

#

should i ping when i get back?

hexed hazel
#

It sounds like some grid-based system for a chess game.
Maybe using a 2D array for those piece movements?

But I haven't seen the chessmen script

scenic swan
#

i have an array for it

#

from 0-7

#

of both x and y

unkempt meadow
scenic swan
hexed hazel
#

I once made a 2D array-based game.
To move things you need to grab ref of the thing that needs to move.
Then grab the destination.

Since chess doesn't have pieces swapping places you don't need to save stuff temporarily to move things, I think?

So it should be enough to just overwrite whatever is in the destination with the piece you are moving, and then empty (null) the slot the piece was originally at.

Though maybe this game uses a diff system than I did.
Mine was based on a bejeweled tut that I used as a base for a Tetris att/puyo style thing.

scenic swan
#

that is swapping no?

#

but yes

#

i need to make the rook (which is now cp) and change its x by -2

hexed hazel
#

My brain is too overloaded atm to process all this atm.

"cp.matrixX = cp.MatrixX - 2"
To the computer that means "the value "MatrixX, overwrite it with current value of MatrixX - 2"

Gets you the number change at least.

unkempt meadow
#

I'm thinking you'll need something like a GameManager.MovePiece() method... Something along the lines of

public void MovePiece( Vector2Int from, Vector2Int to ) {
  GameObject piece = GetPosition( from.x, from.y );

  if( piece != null ) {
    GameObject pieceAtDestination = GetPosition( to.x, to.y );

    if( pieceAtDestination != null ) {
      // TODO: "take piece" logic.
    }

    positions[to.x][to.y] = piece;
  }
}
scenic swan
#

but idk how to change the matrixX of cp

hexed hazel
#

If it's just a number then you just do "cp.matrixX = cp.MatrixX - 2;"
If it's some array stuff and you need refs then it's harder ye

scenic swan
#

cp has matrixX in the form of GetPosition()

hexed hazel
#

GetPosition() sounds like a function. It probably just spits out two ints, one for X and one for Y.
I dunno what that controller of yours has inside it's script, but it might also have a SetPosition() or w/e.

scenic swan
hexed hazel
#

Oh I see, so the Get version gives you it as 2 ints. X and Y.
The set version takes a GameObject as the input, and uhhh... it allocates cm the component "Chessmen" from the obj...

The part about positions seems to try and fetch the numbers with a GetXBaord() and GetYBoard functions (which are on cm) and assigns... oh god yeah I'm not sure what's going on.

scenic swan
#

lol

#

ima just leave this for later

#

for future Kona

hexed hazel
#

Yeah I'm sure some of the vets here would easily read this but I'm not experienced enough. lol
Like I can write this sort of stuff in a week or two but yeah it's a bit much for me to read through in hours rather than days.

livid hound
#

I do think that's better to move your pieces like that, future @scenic swan:

using UnityEngine;

public class ChessPiece : MonoBehaviour
{
    private int x, y; range (1 to 8)
    private float xDistance, yDistance; // those values are width and height of 1 chess square respectfully

    // x and y range from -7 to 7 (because chess board is 8x8)
    public void MovePiece(int xSteps, int ySteps)
    {
        x += xSteps;
        y += ySteps;
        
        transform.position.x += xDistance * xSteps;
        transform.position.y += yDistance * ySteps;
    }

    public (int x, int y) GetPosition() => (x, y);
}