Advertisement
kemonologic

ds_grid_find_value_arr

Feb 27th, 2022
2,783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @func ds_grid_find_value_arr
  2. /// @arg {grid} id
  3. /// @arg {any} value
  4. /// @desc Returns an array containing an array for each x/y position the target value was found in the grid.
  5.  
  6. var _id = argument[0];
  7. var _value = argument[1];
  8.  
  9. var _resultArr = [];
  10. var _fndCnt = 0;
  11.  
  12. if (!ds_exists(_id,ds_type_grid)){
  13.     return -1;
  14. }
  15.  
  16. var _gridW = ds_grid_width(_id);
  17. var _gridH = ds_grid_height(_id);
  18.  
  19. if (!ds_grid_value_exists(_id,0,0,_gridW - 1,_gridH - 1,_value)){
  20.     return _resultArr;
  21. }
  22.  
  23. for (var _yy = 0; _yy < _gridH; _yy++){
  24.     if (ds_grid_get_max(_id,0,_yy,_gridW - 1,_yy) == 0 && _value > 0){ // Skip row
  25.         continue;  
  26.     }
  27.     for (var _xx = 0; _xx < _gridW; _xx++){
  28.         if (_id[# _xx, _yy] == _value){
  29.             _resultArr[_fndCnt] = [_xx, _yy];  
  30.             _fndCnt++;
  31.         }
  32.     }
  33. }
  34.  
  35. return _resultArr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement