我有一个函数来创建一个文本框对象并设置其值,但创建事件在此之前运行。这是功能代码:
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;
如何在设置变量后运行create事件?
instance_create
在返回之前运行Create事件,因此在Create事件运行时不会设置之后分配的变量。
我有一篇关于此事的旧博客文章;最简单的方法是将您想要的init存储在一个全局变量中,假设
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;
// ...