So hello everybody, I am struggling with very strange problem in my code, my object has a variable Path, when I change the state (the step event script) of this object to my PathMovement it does this
, but then when it executes this code in step event :
And what happens: see the temporary variable _tilePath, it actually gets the index of 0, just like the varible path, so when I change the var _tilePath, the changes also effect path, I checked it using debug mode, see the variable lastIndex is actually the size
GML:
path = ds_list_create
Code:
var ttX=ScreenTo_tX(mouse_x,mouse_y);
var ttY=ScreenTo_tY(mouse_x,mouse_y);
ttX=clamp(ttX,0,MAP_W);
ttY=clamp(ttY,0,MAP_H);
var _target=global.theMap[# ttX,ttY];
if(!_target[TILE.COL] && _target!=currentTile)
{
var _path=path_add();//Don't confuse this variable with my path ds_list, this is just for pathmaking
var _tilePath=ds_list_create();//Index of _tilePath = 0 and index of Path = 0
var _pathExists=false;
var lastTile=currentTile;
var lastIndex=ds_list_size(path)-1 //see, here the lastIndex=-1 as the path ds_list is empty so its size = 0
if(!ds_list_empty(path)) lastTile=path[| lastIndex]
_pathExists=mp_grid_path(global.path_grid,_path,lastTile[TILE.tX]*TILE_W,lastTile[TILE.tY]*TILE_W,_target[TILE.tX]*TILE_W,_target[TILE.tY]*TILE_W,true);
for(var i=1;i<path_get_number(_path);i++)
{
var _tX=floor(path_get_point_x(_path,i)/TILE_W);
var _tY=floor(path_get_point_y(_path,i)/TILE_W);
var _tile=global.theMap[# _tX,_tY];
ds_list_add(_tilePath,_tile);
}
path_delete(_path);
var lastIndex=ds_list_size(path)-1
//And See now Here the var lastIndex = the size of _tilePath -1, because they are actually one ds_list,
// but I haven't made any of them point the other one
//Rest of code...