game-maker-studio-2 - 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_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;
}
}
解决方案
从 GMS2 2.3.0 开始,GMS2 中的脚本需要在函数内。
通常这些脚本应该已经被自动转换了,但也许这并没有发生在你身上。
尝试制作一个新脚本,该函数将出现在那里(以及关于新脚本的评论中的一条消息),您将能够在该函数中分配参数。
推荐阅读
- c++ - 使 \page 和 \subpage 参考 doxygen 中的方法文档
- c++ - 在 C++ 中返回不正确的楼层函数值
- linux - CentOS yum 失败并出现 libcurl.so.4 错误,提示“未定义符号:libssh2_agent_disconnect”
- android - 更新 Android Room 数据库中的多个表
- php - 未捕获的 TYPO3 异常:#1472074485:表 'db.tx_sfregister_domain_model_frontenduser' 不存在...?
- python - 如何在一小时的数据框熊猫中找到平均值和最大值?
- javascript - 如何检查样式是否在元素上定义而不是继承?
- java - Java:是否可以对其实现类的客户端隐藏超级接口?
- excel - 如何使用 Powershell 关闭特定的 Excel 文件
- java - 为什么来自消息源的自定义消息不适用于请求参数验证?