GMS2 参数总是返回 undefined

问题描述

我是 Game Maker Studio 2 的新手,每当我尝试使用 scr_tile_collision(collision_tile_map_id,16,veLocity_[vector2_x]); 调用我的脚本时,它都会指出参数未定义。在我的脚本中,我有以下内容,无论我是否将变量设置为本地变量,脚本似乎都无法检测到参数。

/// @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_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_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_bottom-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_top]);
    if tile_top {
        y = bBox_top & ~(tile_size-1);
        y += tile_size+y-bBox_top;
        veLocity[@ vector2_y] = 0;
    }
}

解决方法

从 GMS2 2.3.0 开始,GMS2 中的脚本需要在函数内。

通常这些脚本应该已自动转换,但您可能没有这样做。
尝试创建一个新脚本,该函数将出现在那里(以及有关新脚本的注释中的消息),您将能够在该函数中分配参数。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...