0

我有一个函数来创建一个文本框对象并设置它的值,但创建事件在此之前运行。这是功能代码:

text_obj = instance_create(0, 0, obj_character_text);
text_obj.text = text;
text_obj.face = face;
text_obj.name = name;

这是创建事件:

current_text_index = 0;
current_text = string_char_at(text, current_text_index);
alarm[0] = 5;

设置变量后如何让创建事件运行?

4

1 回答 1

0

instance_create在返回之前运行 Create 事件,因此之后分配的变量不会在 Create 事件运行时设置。

我有一篇关于此事的旧博客文章;最简单的方法是将所需的初始化存储在全局变量中,假设

global.character_text_init = { text: text, face: face, name: name };

并在创建

var init = global.character_text_init;
global.character_text_init = undefined; // so that we get a clean error if we forget
text = init.text;
face = init.face;
name = init.name;
// ...
于 2022-01-05T13:47:55.687 回答