[SOLVED] Path Tool (GMS2)

L

LWDIV

Guest
I need help by solving the error:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Key Press Event for <Space> Key
for object object0:
Unable to find any instance for object index '2' name '<undefined>'
at gml_Object_object0_KeyPress_32 (line 13) - currentPath = path2.path_index;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_object0_KeyPress_32 (line 13)

___________________________________________

I setted up a fresh project with two objects. One oject is a red square to make it move on the path0, path1, path2 or path3. The second object is holding two globalvars currentLevel and currentPath. Depends on what level 0 to 3 currentLevel is set to, i am changing the path. Code below:

object1 code:
CreateEvent ->


globalvar currentPath;
currentPath = path0.path_index;
globalvar currentLevel;
currentLevel = 0;

object0 code:
spacebar pressed event ->


currentLevel = 0;

currentPath.path_endaction = path_action_stop;

if (currentLevel = 0) {
currentPath = path0.path_index;
path_start(path0, 2, path_action_reverse, false);
} else if (currentLevel = 1){
currentPath = path1.path_index;
path_start(path1, 2, path_action_reverse, false);
} else if (currentLevel = 2){
currentPath = path2.path_index;
path_start(path2, 2, path_action_reverse, false);
} else if (currentLevel = 3){
currentPath = path3.path_index;
path_start(path3, 2, path_action_reverse, false);
}
if (currentLevel < 4) {
currentLevel++;
} else {
currentLevel = 0;
}

What do i wrong? :(
 
Paths are not objects. You can't use the "." operator on them. Paths do not have a property called "path_index", "path_index" is a built-in variable that objects have.

When you are referring to a path, you just use the name of the path by itself, such as path0, path1, etc...

Trying to use the "." operator on a path name will confuse GameMaker, it will try to use the value of the path name as an object instead.

Code:
currentPath = path0.path_index;
should be:

Code:
currentPath = path0;
and so on... for all the other places where you refer to paths by their name.

Code:
currentPath.path_endaction = path_action_stop;
Same for this, you only assign a path end action when you call path_start(), outside of this function, "path_endaction" by itself has no meaning. Instead, GameMaker will try to find an instance which has an object_index of whatever the value of currentPath is, and then create a variable called "path_endaction" in that instance.
 
L

LWDIV

Guest
Nice, now it works! Thank you very much :) ..also replaced "currentPath.path_endaction = path_action_stop;" with path_end().
 
Top