game-maker-studio-2game-maker-language

GMS2 Argument always returns undefined


I'm new to Game Maker Studio 2, whenever I try to call my script with scr_tile_collision(collision_tile_map_id, 16, velocity_[vector2_x]);, it states that the arguments are undefined. In my script I have the following, no matter whether I make the variables local or not, the script cannot seem to detect the params.

/// @param tile_map_id
/// @param tile_size
/// @param velocity_array


var tile_map_id = argument0;
var tile_size = argument1;
var velocity = argument2;

// For the velocity array
var vector2_x = 0;
var vector2_y = 1;

show_debug_message(tile_map_id); // no matter which variable is placed here, it is undefined.

// Move horizontally
x = x + velocity[vector2_x];

// Right collisions
if velocity[vector2_x] > 0 {
    var tile_right = scr_collision(tile_map_id, [bbox_right-1, bbox_top], [bbox_right-1, bbox_bottom-1]);
    if tile_right {
        x = bbox_right & ~(tile_size-1);
        x -= bbox_right-x;
        velocity[@ vector2_x] = 0;
    }
} else {
    var tile_left = scr_collision(tile_map_id, [bbox_left, bbox_top], [bbox_left, bbox_bottom-1]);
    if tile_left {
        x = bbox_left & ~(tile_size-1);
        x += tile_size+x-bbox_left;
        velocity[@ vector2_x] = 0;
    }
}

// Move vertically
y += velocity[vector2_y];

// Vertical collisions
if velocity[vector2_y] > 0 {
    var tile_bottom = scr_collision(tile_map_id, [bbox_left, bbox_bottom-1], [bbox_right-1, bbox_bottom-1]);
    if tile_bottom {
        y = bbox_bottom & ~(tile_size-1);
        y -= bbox_bottom-y;
        velocity[@ vector2_y] = 0;
    }
} else {
    var tile_top = scr_collision(tile_map_id, [bbox_left, bbox_top], [bbox_right-1, bbox_top]);
    if tile_top {
        y = bbox_top & ~(tile_size-1);
        y += tile_size+y-bbox_top;
        velocity[@ vector2_y] = 0;
    }
}


Solution

  • As of GMS2 2.3.0, the scripts in GMS2 needs to be within functions.

    Normally these scripts should've been converted automatically, but perhaps that didn't happened for you.
    Try making a new script, and the function will appear there (along with a message in the comments about the new scripts), and you'll be able to assign parameters within that function.