Post by spiceboy on Nov 3, 2021 19:21:06 GMT
I'm having an odd bug in my own codebase, which has taken a lot from your own codebase (thanks a bunch for the tutorials!).
Whenever the AI moves (and ONLY when the AI moves), the starting location for a turn gets assigned to the position of the end tile! For example, if the unit starts at a tile with coordinates (4,3), and the AI chooses to move to (5,2), the original tile (4,3) will now have position (5,2). The tile is then essentially taken out of the flow of battle, as it cannot be individually selected.
This does not appear to be a problem with the tutorial codebase, as I tested that (as have many others) and it works fine. I'm confused about where I may have introduced this bug in my own code, since there are very few modifications to anything regarding movement in my own codebase. I have not made any modifications to the AI code at all. I've made a modification to the traversal code which passes in a delegate for the cost of travelling across a tile, but I don't believe this would assign any tile positions to anything else, or this bug would appear when the player moves as well.
I've done some debugging, and I can determine that the assignment appears to take place in MoveTargetState:ComputerSimulateMove(). Here's the snippet of my code, which has a few added debug statements and changed variable names;
The position of the tile changes in between the two debug statements, though I am not sure why. At first I suspected SelectTile() might have changed some values, but it only modifies the cursorPosition passed in to it.
I understand this is a rather open-ended question and hard to answer considering it's a bug I introduced, but any thoughts on where to debug next would be greatly appreciated. I'm having a difficult time finding any spot in the code where a tile's position would be modified at all. I'm wondering if there's some C# intricacy regarding assignments that I'm not aware of.
Whenever the AI moves (and ONLY when the AI moves), the starting location for a turn gets assigned to the position of the end tile! For example, if the unit starts at a tile with coordinates (4,3), and the AI chooses to move to (5,2), the original tile (4,3) will now have position (5,2). The tile is then essentially taken out of the flow of battle, as it cannot be individually selected.
This does not appear to be a problem with the tutorial codebase, as I tested that (as have many others) and it works fine. I'm confused about where I may have introduced this bug in my own code, since there are very few modifications to anything regarding movement in my own codebase. I have not made any modifications to the AI code at all. I've made a modification to the traversal code which passes in a delegate for the cost of travelling across a tile, but I don't believe this would assign any tile positions to anything else, or this bug would appear when the player moves as well.
I've done some debugging, and I can determine that the assignment appears to take place in MoveTargetState:ComputerSimulateMove(). Here's the snippet of my code, which has a few added debug statements and changed variable names;
Debug.Log("At the beginning of ComputerSimulateMove, unit is at: " + turn.actor.tileOccupying.position);
Point cursorPosition = position;
while (cursorPosition != turn.plan.moveLocation)
{
if (cursorPosition.x < turn.plan.moveLocation.x) cursorPosition.x++;
if (cursorPosition.x > turn.plan.moveLocation.x) cursorPosition.x--;
if (cursorPosition.y < turn.plan.moveLocation.y) cursorPosition.y++;
if (cursorPosition.y > turn.plan.moveLocation.y) cursorPosition.y--;
SelectTile(cursorPosition);
yield return new WaitForSeconds(0.25f);
}
Debug.Log("At the end of ComputerSimulateMove, unit is at: " + turn.actor.tileOccupying.position);
yield return new WaitForSeconds(0.5f);
owner.ChangeState<MoveSequenceState>();
The position of the tile changes in between the two debug statements, though I am not sure why. At first I suspected SelectTile() might have changed some values, but it only modifies the cursorPosition passed in to it.
I understand this is a rather open-ended question and hard to answer considering it's a bug I introduced, but any thoughts on where to debug next would be greatly appreciated. I'm having a difficult time finding any spot in the code where a tile's position would be modified at all. I'm wondering if there's some C# intricacy regarding assignments that I'm not aware of.