You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GameMaker函数导致YoYo Compiler编译失败但VM运行正常问题求助

YYC编译失败但VM正常运行的问题(Pizza Tower Online模组开发)

我正在制作《Pizza Tower Online》的模组,遇到异常:YoYo Compiler(YYC)编译失败,但虚拟机(VM)可正常运行。使用的是GameMaker 2022.0.0.12 Runtime和2022.0.0.19 IDE。尝试过将|=语句改为result ||、添加保底的return false;、初始化result = false;等操作,均未解决问题。

引发问题的代码片段:

function instance_in_camera(inst = id, cam = view_camera[0])
{
    var camx = camera_get_view_x(cam);
    var camy = camera_get_view_y(cam);
    var camw = camera_get_view_width(cam);
    var camh = camera_get_view_height(cam);

    var result = false;
    var xx = inst.x - sprite_get_xoffset(inst.sprite_index);
    var yy = inst.y - sprite_get_yoffset(inst.sprite_index);

    // left bottom
    result = result || point_in_rectangle(xx + sprite_get_bbox_left(inst.sprite_index), yy + sprite_get_bbox_bottom(inst.sprite_index), camx, camy, camx + camw, camy + camh);
    if (result)
        return result;

    // left top
    if (!result)
    {
        result = result || point_in_rectangle(xx + sprite_get_bbox_left(inst.sprite_index), yy + sprite_get_bbox_top(inst.sprite_index), camx, camy, camx + camw, camy + camh);
        if (result)
            return result;
    }

    // right bottom
    if (!result)
    {
        result = result || point_in_rectangle(xx + sprite_get_bbox_right(inst.sprite_index), yy + sprite_get_bbox_bottom(inst.sprite_index), camx, camy, camx + camw, camy + camh);
        if (result)
            return result;
    }

    // right top
    if (!result)
    {
        result = result || point_in_rectangle(xx + sprite_get_bbox_right(inst.sprite_index), yy + sprite_get_bbox_top(inst.sprite_index), camx, camy, camx + camw, camy + camh);
        if (result)
            return result;
    }
    return false;
}

修复方案

  • 添加有效性校验:YYC对变量有效性检查比VM严格,需提前过滤空实例、无效精灵和无效相机,在函数开头插入:

    if (!instance_exists(inst) || inst.sprite_index == no_sprite || cam == noone) {
        return false;
    }
    
  • 简化分支逻辑:旧版本YYC对嵌套分支的优化存在Bug,去掉冗余的if (!result)判断,直接顺序检查(return true会提前终止函数,不影响性能),替换后的完整函数:

    function instance_in_camera(inst = id, cam = view_camera[0])
    {
        if (!instance_exists(inst) || inst.sprite_index == no_sprite || cam == noone) {
            return false;
        }
    
        var camx = camera_get_view_x(cam);
        var camy = camera_get_view_y(cam);
        var camw = camera_get_view_width(cam);
        var camh = camera_get_view_height(cam);
    
        var xx = inst.x - sprite_get_xoffset(inst.sprite_index);
        var yy = inst.y - sprite_get_yoffset(inst.sprite_index);
    
        if (point_in_rectangle(xx + sprite_get_bbox_left(inst.sprite_index), yy + sprite_get_bbox_bottom(inst.sprite_index), camx, camy, camx + camw, camy + camh)) {
            return true;
        }
        if (point_in_rectangle(xx + sprite_get_bbox_left(inst.sprite_index), yy + sprite_get_bbox_top(inst.sprite_index), camx, camy, camx + camw, camy + camh)) {
            return true;
        }
        if (point_in_rectangle(xx + sprite_get_bbox_right(inst.sprite_index), yy + sprite_get_bbox_bottom(inst.sprite_index), camx, camy, camx + camw, camy + camh)) {
            return true;
        }
        if (point_in_rectangle(xx + sprite_get_bbox_right(inst.sprite_index), yy + sprite_get_bbox_top(inst.sprite_index), camx, camy, camx + camw, camy + camh)) {
            return true;
        }
        return false;
    }
    
  • 升级GameMaker版本:你使用的2022早期版本存在多个YYC编译已知Bug,建议升级到同系列的稳定版本(如2022.11.x),能直接修复部分兼容性问题。

内容的提问来源于stack exchange,提问作者Reycko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 16:05:42