#matrixX and matrixY
1 messages · Page 1 of 1 (latest)
hello
hi
what do you do here?
please leave the thread heisenburger
public GameObject GetPosition(int x, int y)
{
return positions[x, y];
}
so you wanna to somehow change x and y values of this method?
GameObject cp = controller.GetComponent<GameManager>().GetPosition(matrixX, matrixY);
i want to change the x and y here
the question is quite unclear
how
i want to know how to access the matrixX and matrixY of cp
and change it
in an if
// you can change it hear, or ??
GameObject cp = controller.GetComponent<GameManager>().GetPosition(thisOne, andThisOne);
you cannot do that if cp is GameObject
if (controller.GetComponent<GameManager>().GetPosition(matrixX, matrixY) == reference.GetComponent<Chessmen>().wRooks[1])
{
matrixX = getBoardX + 2;
cp.idk = getBoardX + 1;
Debug.Log(getBoardX);
}
in there
GameObject does not have those matrixX and matrixY values
yes, you change matrixX of the this script
the script you are actually in now
in code I mean
ya undestood.
idk
it should be smth like this
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)
using UnityEngine;
public class TargetController : MonoBehaviour
{
// those are the values you do can change
public float matrixX, matrixY;
}
i want to put the rook that is on the location of cp and move it
that logic is not good enough
wdym
you need to have script for this
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
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
SetCoords() of Chessmen.cs has x and y variables which is the xDist and yDist
If I'm understanding correctly, you want to update a piece's location within the GameManager.positions array?
kinda?
idk
that was really long sentence to type for 5 min 🫥
Every time I think I've understood, something else was said that made me not so sure 😁
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
kinda
i have an array for it
from 0-7
of both x and y
Maybe using a 2D array for those piece movements?
I think that presently exists -GameManager.positionsis a 2D array ofGameObjects
public GameObject[,] positions = new GameObject[8, 8];
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.
castling
that is swapping no?
but yes
i need to make the rook (which is now cp) and change its x by -2
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.
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;
}
}
something like that
but idk how to change the matrixX of cp
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
this is the problem
GameObject cp = controller.GetComponent<GameManager>().GetPosition(matrixX, matrixY);
cp has matrixX in the form of GetPosition()
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.
public GameObject GetPosition(int x, int y)
{
return positions[x, y];
}
public GameObject controller;
controller = GameObject.FindGameObjectWithTag("GameController");
public void SetPosition(GameObject obj)
{
Chessmen cm = obj.GetComponent<Chessmen>();
positions[cm.GetXBoard(), cm.GetYBoard()] = obj;
}
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.
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.
this script with return positions[x, y] is strange anyway
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);
}