简体   繁体   中英

how to get a object to initialize object with variables set in gms

I have a function to create a textbox object and set it values but the create event runs before that. this is the function code:

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

and this is the create event:

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

How can I get the create event to run after the variables have been set?

instance_create runs the Create event before returning, so variables assigned afterwards would not be set as of the Create event running.

I have an old blog post about the matter; the easiest is to store your desired init in a global variable, suppose

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

and in Create

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;
// ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM