Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @func ds_grid_find_value_arr
- /// @arg {grid} id
- /// @arg {any} value
- /// @desc Returns an array containing an array for each x/y position the target value was found in the grid.
- var _id = argument[0];
- var _value = argument[1];
- var _resultArr = [];
- var _fndCnt = 0;
- if (!ds_exists(_id,ds_type_grid)){
- return -1;
- }
- var _gridW = ds_grid_width(_id);
- var _gridH = ds_grid_height(_id);
- if (!ds_grid_value_exists(_id,0,0,_gridW - 1,_gridH - 1,_value)){
- return _resultArr;
- }
- for (var _yy = 0; _yy < _gridH; _yy++){
- if (ds_grid_get_max(_id,0,_yy,_gridW - 1,_yy) == 0 && _value > 0){ // Skip row
- continue;
- }
- for (var _xx = 0; _xx < _gridW; _xx++){
- if (_id[# _xx, _yy] == _value){
- _resultArr[_fndCnt] = [_xx, _yy];
- _fndCnt++;
- }
- }
- }
- return _resultArr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement