• 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 Need help with tutorial

AlfMandoor

Member
Hello to everyone, I really would appreciate any help you can please give me...

From a week ago I have this problem and can´t fix it, and the worst is that the enemy just stay there and don´t do anything, I am been following a tutorial about using platform pathfinding, where the enemy follows you and jump, this is the exact video:
but when trying it I always get this error when calling the script (scr_fill_the_grid) into the step event from object enemy, this is the image from it:
pathfinding.png
and this is the code from the step event:
GML:
if keyboard_check(ord("S"))
{
     /// Reset all variable when we build a new path because enemy might be in path when we press S
     speed_h = 0;
     speed_v = 0;
     if path_exists(path_building) {
         path_delete (path_building);
     }
     path_point = 0 ;
     action = 0 ;
     jump_action = 0 ;

    scr_fill_the_grid(floor(x/O_Grid.cell_width), floor(y/O_Grid.cell_height), floor(O_Player.x/O_Grid.cell_width), floor(O_Player.y/O_Grid.cell_height));
}

// Follow the path if path exists
if path_exists(path_building)
{
    scr_follow_the_path(path_building);
}


// Apply gravity
if !place_meeting (x, y+1, O_Collision)
    {
        speed_v = speed_v + game_gravity ;
    }

// Check if there is a collsiion
scr_collision () ;
He has a tutorial in the game maker community post, this is the link for it, https://forum.yoyogames.com/index.php?threads/platformer-pathfinding-tutorial.43000/
I would please thank you so much your help.
 
Last edited:

AlfMandoor

Member
try restart your project
maybe sometimes that is happen
Hello my friend thank you so much for answering, I already try it but still nothing, and the problem is that it doesn´t work, so the enemy just stay there and it don´t do anything...
 

Roldy

Member
but when trying it I always get this error when calling the script (scr_fill_the_grid) into the step event from object enemy, this is the image from it:
'
What error are you getting when you run the game? Or if it doesn't run what is the compile error?
 

AlfMandoor

Member
'
What error are you getting when you run the game? Or if it doesn't run what is the compile error?
Thank You too so much for answering, is this one:
pathfinding.png
it only says that the number of argument for function(the name of the script) expected 0 got 4, but the strange part is that in the tutorial video it work without having this error. the bad is that the enemy just doesnt follow, jump or do anything
 

Roldy

Member
Thank You too so much for answering, is this one:
View attachment 42169
it only says that the number of argument for function(the name of the script) expected 0 got 4, but the strange part is that in the tutorial video it work without having this error. the bad is that the enemy just doesnt follow, jump or do anything

High, that is not an error, it is a warning. The tutorial you are using is old and much has changed since then. Please read: https://forum.yoyogames.com/index.p...ge-generates-undefined-variable-errors.79907/
 

AlfMandoor

Member
High, that is not an error, it is a warning. The tutorial you are using is old and much has changed since then. Please read: https://forum.yoyogames.com/index.p...ge-generates-undefined-variable-errors.79907/
this is the code I got in my script.
GML:
// Los recursos de Script han cambiado para la v2.3.0 Consulta
// https://help.yoyogames.com/hc/en-us/articles/360005277377 para más información
function scr_fill_the_grid(){
var ax = argument0;   // Start X position
var ay = argument1;    // Start Y position
var xgoal = argument2;   // X Position where we want to go
var ygoal = argument3 ;  // Y Position where we want to go
var path_found ;      // A way was found
var n ;  // Variable when you fall
var a ; // Variable when you fall
path_found = 0;  // 0 means that the path is not found

/// Copy the global pathfinding
ds_gridpathfinding = ds_grid_create(ds_grid_width(global.ds_grid_pathfinding), ds_grid_height(global.ds_grid_pathfinding)) ;
ds_grid_copy (ds_gridpathfinding, global.ds_grid_pathfinding);

/// Add the first point into the list
var point_list = ds_list_create() ;
ds_list_add (point_list, ax);
ds_list_add (point_list, ay);
ds_grid_set(ds_gridpathfinding,ax,ay,0);

for (var i=1; i<200; i+=1)
{
    if path_found == 1 {
    ds_list_destroy(point_list); // We don't need the list anymore because we find a path.
    ///ds_grid_destroy(ds_gridpathfinding); /// Grid has to be delete. We keep it only for debuger purposes
    return path_found ;
    break ;
    }

var size_list = ds_list_size(point_list) ;  // Update the size of the list. It is for delete all the previous points.

if size_list == 0 {    // When size list is zero, it means that, we check all the positions where the enemy could go, and no one is the goal position
ds_list_destroy(point_list);   // Destroy the list because it takes up memory and we don't need it anymore.
ds_grid_destroy(ds_gridpathfinding); // // Destroy the grid because it takes up memory.
return path_found ;  /// It will return 0, so if script returns 0, it means that no path was found to reach the goal.
break ;
}


for (var j=0; j<size_list; j+=2){
        ax = ds_list_find_value(point_list,j)
        ay = ds_list_find_value(point_list,j+1)

        if ax==xgoal && ay==ygoal {
        path_found = 1 ;
        scr_build_the_path(xgoal,ygoal);
        break ;
        }

n=1 ; /// Variable for the Fall

/// Check if the enemy can go to the right
if ds_grid_get(ds_gridpathfinding,ax+1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax+1,ay+1)==-2 {
ds_grid_set(ds_gridpathfinding,ax+1,ay,i);
ds_list_add (point_list, ax + 1);
ds_list_add (point_list, ay);
}

else{   /// If the enemy can go to the right, the other movement will be impossible. So we can put a else to skip all the following code

/// Check if we can go jump one block vertically (right side)
if (ds_grid_get(ds_gridpathfinding,ax+1,ay)==-2 && ds_grid_get(ds_gridpathfinding,ax+1,ay-1)==-1)
            {
            ds_grid_set(ds_gridpathfinding,ax+1,ay-1,i);
            ds_list_add (point_list, ax + 1);
            ds_list_add (point_list, ay-1);
            }
else {  /// If the ennemy can go jump one block horizontally, the others movement will be impossible. So we can put a else to skip all the following code

/// Check if the enemy can do a diagonal jump (Big Jump). (Right side);
if ds_grid_get(ds_gridpathfinding,ax+1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax+2,ay)==-2 && ds_grid_get(ds_gridpathfinding,ax+2,ay-1)==-1
        {
        ds_grid_set(ds_gridpathfinding,ax+2,ay-1,i);
        ds_list_add (point_list, ax + 2);
        ds_list_add (point_list, ay-1);
        }

///Check if the enemy can jump horizontally (jump over a void). (Right side)
if ds_grid_get(ds_gridpathfinding,ax+1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax+2,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax+2,ay+1)==-2
        {
        ds_grid_set(ds_gridpathfinding,ax+2,ay,i);
        ds_list_add (point_list, ax + 2);
        ds_list_add (point_list, ay);
        }

/// Check if the enemy can fall (Right side).
if ds_grid_get(ds_gridpathfinding,ax+1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax+1,ay+1)==-1
            {
                    {
                    do
                       {
                       n=n+1 ;
                       a = ds_grid_get(ds_gridpathfinding,ax+1,ay+n);
                       }
                    until (a==-2) ||  (ay+n == ds_grid_height(ds_gridpathfinding)) }
                   
        if ds_grid_get(ds_gridpathfinding,ax+1,ay+n-1)==-1 && ds_grid_get(ds_gridpathfinding,ax+1,ay+n)== -2
            {
            ds_grid_set(ds_gridpathfinding,ax+1,ay+n-1,i);
            ds_list_add (point_list, ax + 1);
            ds_list_add (point_list, ay+n-1);
            }
        }
    }
}


n=1 ; /// Re-initialize variable for the Fall (left side)

/// Check if the enemy can go to the left
if ds_grid_get(ds_gridpathfinding,ax-1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax-1,ay+1)==-2 {
ds_grid_set(ds_gridpathfinding,ax-1,ay,i);
ds_list_add (point_list, ax -1);
ds_list_add (point_list, ay);
}
else{

/// Check if we can go jump one block vertically (left side)
if ds_grid_get(ds_gridpathfinding,ax-1,ay)==-2 && ds_grid_get(ds_gridpathfinding,ax-1,ay-1)==-1{
ds_grid_set(ds_gridpathfinding,ax-1,ay-1,i);
ds_list_add (point_list, ax-1);
ds_list_add (point_list, ay-1);
}
else {

/// Check if the enemy can do a diagonal jump (Big Jump). (left side);
if ds_grid_get(ds_gridpathfinding,ax-1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax-2,ay)==-2 && ds_grid_get(ds_gridpathfinding,ax-2,ay-1)==-1{
ds_grid_set(ds_gridpathfinding,ax-2,ay-1,i);
ds_list_add (point_list, ax-2);
ds_list_add (point_list, ay-1);
}

///Check if the enemy can jump horizontally (over a void). (left side)
if ds_grid_get(ds_gridpathfinding,ax-1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax-2,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax-2,ay+1)==-2{
ds_grid_set(ds_gridpathfinding,ax-2,ay,i);
ds_list_add (point_list, ax-2);
ds_list_add (point_list, ay);
}

/// Check if the enemy can fall (left side).
if ds_grid_get(ds_gridpathfinding,ax-1,ay)==-1 && ds_grid_get(ds_gridpathfinding,ax-1,ay+1)==-1
            {
                {
                do
                   {
                   n=n+1 ;
                   a = ds_grid_get(ds_gridpathfinding,ax-1,ay+n);
                   }
                until (a=-2) || (ay+n==ds_grid_height(ds_gridpathfinding))}  
                    if ds_grid_get(ds_gridpathfinding,ax-1,ay+n-1)==-1 && ds_grid_get(ds_gridpathfinding,ax-1,ay+n)== -2
                    {
                    ds_grid_set(ds_gridpathfinding,ax-1,ay+n-1,i);
                    ds_list_add (point_list, ax-1);
                    ds_list_add (point_list, ay+n-1);
                    }
            }
        }
    }
}
/// Delete all the previous points
for (var k=0; k< size_list; k+=1)
    {
    ds_list_delete (point_list, 0);
    }
}
}
 

AlfMandoor

Member
Maybe. You didn't show the script.

But the tutorial is using an older style so it is likely confusing.
I even have a warning in the script, in the part that says (scr_build_the_path(xgoal,ygoal) and it is the same warning, that I cant have anything when calling a script, because it says that it expect 0 arguments
 

Roldy

Member
I even have a warning in the script, in the part that says (scr_build_the_path(xgoal,ygoal) and it is the same warning, that I cant have anything when calling a script, because it says that it expect 0 arguments
read that thread I posted. Most likely all you need to do is put the arguments in the functions paranthesis:

GML:
function scr_fill_the_grid(ax, ay, xgoal, ygoal){ // Put arguements here

// Don't use this old 'argumentx' syntax, just comment it away
/*
var ax = argument0;   // Start X position
var ay = argument1;    // Start Y position
var xgoal = argument2;   // X Position where we want to go
var ygoal = argument3 ;  // Y Position where we want to go
*/
 

AlfMandoor

Member
read that thread I posted. Most likely all you need to do is put the arguments in the functions paranthesis:

GML:
function scr_fill_the_grid(ax, ay, xgoal, ygoal){ // Put arguements here

// Don't use this old 'argumentx' syntax, just comment it away
/*
var ax = argument0;   // Start X position
var ay = argument1;    // Start Y position
var xgoal = argument2;   // X Position where we want to go
var ygoal = argument3 ;  // Y Position where we want to go
*/
Thank you so, but so much my friend, you seriously just save my life... I dont have any warning again, I will give you a like, hope I could a give you more, again thank you so much, have a wonderful day.
 
Top