GameMaker Creating random spots for the ai to go to? (mp_grid)

PlayerOne

Member
So far I've got the hang of using mp_grid functions. Now I'm wondering on how create a random predetermined spot on the mp_grid for an enemy to go to.

The idea is for the enemy to randomly change positions after a count reaches zero in the battle arena. Once then the enemy goes to a different position the counter resets and the cycle repeats.

The problem I have is trying to make these make these positions on the grid. Except I'm unsure as to how to achieve this.
 
Last edited:

SoVes

Member
So far I've got the hang of using mp_grid functions. Now I'm wondering on how create a random predetermined spot on the mp_grid for an enemy to go to.

The idea is for the enemy to randomly change positions after a count reaches zero in the battle arena. Once then the enemy goes to a different position the counter resets and the cycle repeats.

The problem I have is trying to make these make these positions on the grid. Except I'm unsure as to how to achieve this.
you can use random range and round it.
Code:
grid[# round(random_range(ds_grid_width(grid))), round(random_range(ds_grid_height(grid)))]
 

PlayerOne

Member
you can use random range and round it.
Code:
grid[# round(random_range(ds_grid_width(grid))), round(random_range(ds_grid_height(grid)))]
There seems to a syntax error in the code you posted. Despite the fact there isn't any out of place or missing brackets.

Edit: You missed an argument in random_range. Replaced with random instead to see if I get any results.
 
Last edited:

PlayerOne

Member
Okay here is snipped of my code. So far (assuming this works) I need to find the x and y of cell and check if its empty.

Code:
var _xx = //NULL
  var _yy = //NULL
   var path = path_add()
   mp_grid_path(global.battle_grid, path, x, y, _xx, _yy, 1)
   path_start(path, 2, 3, 0);
   countdown=5
 
Last edited:

PlayerOne

Member
If anyone can inform me on how to get x and y positions in a 30 by 15 mp_grid, it would help my ai issue.

I only got the first square in the grid, but don't know how to get the correct number when dividing the rest of the room into 64x64 squares.
Code:
round(random_range((room_width-256+32),(?????)))
 
Top