Game Maker Studio 2 数组采用错误的值

Game Maker Studio 2 Array taking wrong values

大家好,我是 Game Maker Studio 的新手,也是该语言的新手。我在做游戏,一直在研究对话系统。

这段代码是为角色对一组选择作出反应而设计的,对话从打印出 line_array 的第一个元素开始,它确实如此,然后让玩家选择两个反应来自 response_array,而是打印出 line_array 的第二个元素,我不明白为什么。

参数是否只包含数组的一个元素?我正在一个对象 oCivilian2 中初始化两个数组,并通过链接到另一个对象 oRespond 的代码 DialogueCode 推送它们,该对象应该允许我筛选游戏中的对话。有什么帮助谢谢

这里是在create of oCivilian2

中初始化的
line_array = [3];
line_array[0] = "Ethan it's good to see you! \n I thought after the incident well.... \n well I thought we had lost you";
line_array[1] = "I've said too much";
line_array[2] = "You hit your head trying to saver her\n It was horrible";
response_array = [2];
response_array[0] = "What happened?";
response_array[1] = "I don't recall alot. How bad was it?";
counter = 0;
x1 = RESOLUTION_W / 2;
y1 = RESOLUTION_H -70;
x2 = RESOLUTION_W/2;
y2 = RESOLUTION_H;
_print = "";
responseSelected = 0;

然后在按下空格键时将其链接到 DialogueCode 的步骤

keyActivate = keyboard_check_pressed(vk_space);
if (keyActivate) 
{
    var inst = collision_rectangle(oPlayer.x+3,oPlayer.y+3,oPlayer.x-3,oPlayer.y-3, oCivilian2, false, false);
    if (inst != noone) 
    {
        ScriptExecuteArray(DialogueCode, line_array);
        ScriptExecuteArray(DialogueCode, response_array);
    }
}

然后通过步进对象oRespond

lerpProgress += (1 - lerpProgress) / 50;
textProgress += global.textSpeed;

x1 = lerp(x1, x1Target,lerpProgress);
x2 = lerp(x2, x2Target,lerpProgress);


keyUp = (keyboard_check_pressed(vk_up)) || (keyboard_check_pressed(ord("W")))
keyDown = keyboard_check_pressed(vk_down) || keyboard_check_pressed(ord("S"));
responseSelected += (keyDown - keyUp);
var _max = 2;
var _min = 0;
if (responseSelected > _max) responseSelected = _min;
if (responseSelected < _min) responseSelected = _max;

for (var i = 0; i < 2; i++) 
{
    var _marker = string_pos(",", response);
    if (string_pos(",",response)) 
    {
        responseScript[i] = string_copy(response,0,_marker);
        string_delete(response,0,_marker);
        var _marker = string_pos(",", response);
    }
    else 
    {
        responseScript[i] = string_copy(response,0, string_length(response));
    }
}
if (keyboard_check_pressed(vk_space))
{
    counter++;
}

然后在oRespond

中打印
/// text
//response 
NineSliceBoxStretched(sTextBox, x1,y1,x2,y2, 0);
draw_set_font(fText);
draw_set_halign(fa_center);
draw_set_valign(fa_top);
draw_set_color(c_black);
if (counter % 2 == 0) 
{
    var _i = 0;
    var _print = string_copy(text,1,textProgress);
    
    draw_text((x1+x2) / 2, y1 + 8, _print);
    draw_set_color(c_white);
    draw_text((x1+x2) / 2, y1 + 7, _print);
    _i++;
}
else 
{
    if (array_length_1d(responseScript) > 0) 
    {
        var _print = "";
        for (var t = 0; t < array_length_1d(responseScript); t++)
        {
            _print += "\n";
            if (t == responseSelected) _print += "--> "
            _print += responseScript[t];
            show_debug_message(responseScript[t]);
            if (t == responseSelected) _print += " <-- "
        }
        draw_text((x1+x2) / 2, y1 + 8, _print);
        draw_set_color(c_white);
        draw_text((x1+x2) / 2, y1 + 7, _print);
    }
}

好的,我认为您的代码存在很多问题。

首先,由于 GM 中的数组是动态声明的,因此

line_array[3]

是一种不好的做法(在我看来)

我从来没有在 GM 中以这种方式声明数组,所以这可能是这里的问题。

其次,我不太理解你的代码逻辑,总是创建对象,至少在 GM 环境中,对应于“物理”实体,我会为平民创建一个对象,而不是为“响应”。

我已经把你的代码改红了很多次,因为在 3 个月内没有人回答你,我可以假设这是因为没有人能真正理解你的编码方式,这种编码方式可能会给你很多未来的问题。如果层次结构良好,您尝试做的事情可能是 super-easy。

我想帮助你处理这段代码,但我觉得它很混乱。

如果您还没有解决这个问题,请发表评论:)

我建议你完全re-implement它,即使无论如何解决。