Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 滚动数组_Arrays_Loops_Game Maker - Fatal编程技术网

Arrays 滚动数组

Arrays 滚动数组,arrays,loops,game-maker,Arrays,Loops,Game Maker,所以我在GameMaker中有一个项目,它有一个聊天室。此操作的消息存储在一个数组中。我希望能够滚动浏览此阵列,以便查看早期的聊天信息 这就是我目前拥有的: 创建事件 chatLog[0] = ""; chatIndex = 0; if (chatIndex > 0) { if (mouse_wheel_down()) { chatIndex--; } } if (chatIndex < array_length_1d(chatLog) - 1)

所以我在GameMaker中有一个项目,它有一个聊天室。此操作的消息存储在一个数组中。我希望能够滚动浏览此阵列,以便查看早期的聊天信息

这就是我目前拥有的:

创建事件

chatLog[0] = "";
chatIndex  = 0;
if (chatIndex > 0) {
    if (mouse_wheel_down()) {
        chatIndex--;
    }
}

if (chatIndex < array_length_1d(chatLog) - 1) {
    if (mouse_wheel_up()) {
        chatIndex++;
    }
}

var _maxLines = 5;
for (i = 0; i < _maxLines; i++) {
    if (i > (array_length_1d(chatLog) - 1)) { exit; }

    var _chatLength = array_length_1d(chatLog) - 1;
    draw_text(0, 50 - chatHeight, chatLog[_chatLength - i + chatIndex]);
}
步骤事件

chatLog[0] = "";
chatIndex  = 0;
if (chatIndex > 0) {
    if (mouse_wheel_down()) {
        chatIndex--;
    }
}

if (chatIndex < array_length_1d(chatLog) - 1) {
    if (mouse_wheel_up()) {
        chatIndex++;
    }
}

var _maxLines = 5;
for (i = 0; i < _maxLines; i++) {
    if (i > (array_length_1d(chatLog) - 1)) { exit; }

    var _chatLength = array_length_1d(chatLog) - 1;
    draw_text(0, 50 - chatHeight, chatLog[_chatLength - i + chatIndex]);
}
if(聊天索引>0){
如果(鼠标滚轮向下()){
查特指数--;
}
}
if(chatIndex(数组长度(chatLog)-1)){exit;}
var\u chatLength=array\u length\u 1d(chatLog)-1;
绘制文本(0,50-聊天高度,聊天日志[\u-chatLength-i+chatIndex]);
}

首先,为了方便在前面添加消息/从后面删除消息(如果消息太多),我们假设日志是一个列表,项目0是最新消息

chatLog = ds_list_create();
chatIndex = 0;
for (var i = 1; i <= 15; i++) {
    ds_list_insert(chatLog, 0, "message " + string(i));
}

太棒了!其中有几件事我确实考虑过自己,例如使用
ds_列表
,而不是
数组
。就像增加的能够以设定的增量滚动的功能一样。非常感谢您的帮助,在我的项目中,所有这些都非常有效!:)