• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED issue with mp_potential_step_object

Avram

Member
Hi all,

Can someone look at this code and please let me know what I'm doing incorrectly? What it *should* do is send my NPCs to a randomly chosen instance of a door but I receive the following error:

############################################################################################
ERROR in
action number 1
of Step Event0
for object obj_pedestrian_smart:

Unable to find instance for object index -4
at gml_Object_obj_pedestrian_smart_Step_0 (line 3) - mp_potential_step(inst.x, inst.y, 1, 1);
############################################################################################
gml_Object_obj_pedestrian_smart_Step_0 (line 3)

Here is the code I'm using:

CREATE
GML:
door_to_go = instance_find(obj_door_exit, irandom(instance_number(obj_door_exit) - 1));
STEP
GML:
inst = door_to_go;

mp_potential_step(inst.x, inst.y, 1, 1);
mp_potential_step_object (inst.x, inst.y, 1, obj_block);
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You are not checking for what happens if the door doesn't exist. The code is assuming it always does, but the error is saying otherwise. Simply wrap the check in a call to instance_exists, eg:
GML:
if instance_exists(door_to_go)
{
mp_potential_step_object(door_to_go.x, door_to_go.y, 1, obj_block);
}
Also note that using mp_potential_step() before the object function does nothing. Use one or the other... Also no need for the inst variable.
 

Avram

Member
Thank you for the prompt reply! I will try this out later when I’m back on my PC.
Incidentally, I am using this method of pathfinding because I assume the mp_grid/A* method doesn’t allow to send NPCs to different locations simultaneously?
 

O.Stogden

Member
Thank you for the prompt reply! I will try this out later when I’m back on my PC.
Incidentally, I am using this method of pathfinding because I assume the mp_grid/A* method doesn’t allow to send NPCs to different locations simultaneously?
The mp_grid functions work hand-in-hand with the path system.

The mp_grid_create just creates a grid which has "valid" places and "invalid" places (usually walls etc.). Each object using the grid (in your case your NPC's) would have a "path" for itself, it can then use the grid to create a valid path between places on the grid, whilst avoiding the walls, using the mp_grid_path function. It's generally much better than mp_potential_* functions, but I imagine it takes more processing power.
 

Avram

Member
Thanks, everyone. What's strange is that the NPCs now just stay in one position, so I'm going to try using mp_grid instead.
 

Avram

Member
Ugh. I was referring to the wrong object name. Changed it, and it works fine. Thanks again, everyone!
 
Top