• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker changing room does not happen until after event?

S

Shadowblitz16

Guest
does anybody know how to get around my object being deleted after I change rooms?

Code:
//Goto Room
room = rm_menu;

//Toolbar
tools_menu = new_item(0, 2,  0, Item_Toolbar_Menu,  new_exit(6,6,5,1));

//Menus
menu_tiles = new_item(0, 16, 6, Item_Option_Tileset, new_exit(0,0,6,6));
Code:
/// @description new_item()
/// @param x
/// @param y
/// @param index
/// @param object
/// @param item_exit

var xx        = argument[0];
var yy        = argument[1];
var index     = argument[2];
var object    = argument[3];
var item_exit = argument[4];

var inst = instance_create_depth(x+xx, y+yy, -1, object);
    inst.index     = index;
    inst.item_exit = item_exit;
    inst.parent    = id;
   
   
return inst;
Code:
/// @description new_exit()
/// @param up
/// @param down
/// @param left
/// @param right

var up = argument[0];
var down = argument[1];
var left = argument[2];
var right = argument[3];

var data;
    data[0] = up;
    data[1] = down;
    data[2] = left;
    data[3] = right;
   
return data;
when I call the editor_goto_menu it doesn't set the room until after the script is finished instead of changing the room and then creating the objects.

I'm not sure if this gamemaker was programmed to do this intentionally but it should not work this way.
 
S

Shadowblitz16

Guest
I did but then I can't set set variables with the instance id it returns, since the instance's don't exist in the room currently running.
 

rIKmAN

Member
Store them in a list and create them from the list once the room has been changed using instance_add().
 
S

Shadowblitz16

Guest
can you give me an example of whats wrong with my code? I'm trying to do this in one controller object

basicly I want to make a event driven editor that uses keyboard and joypads for input
I want to handle the editor init and update in scripts based on cur_menu and cur_item

however I am very bad at menus because of the complexity of the structuring

Code:
/// @description Editor Create
// You can write your code in this editor
#macro CURRENT -42

cur_menu    = 0;
cur_item    = 0;

old_menu    = cur_menu;
old_item    = cur_item;

menu_changed   = false;
item_changed   = false;

rooms = ds_list_create();
rooms[| 0] = rm_menu;
rooms[| 1] = rm_tiles;
Code:
/// @description Editor Step
// You can write your code in this editor

menu_changed   = false;
item_changed   = false;

if (cur_menu   != old_menu)   menu_changed   = true;
if (cur_item   != old_item)   item_changed   = true;

old_menu   = cur_menu
old_item   = cur_item

switch(cur_menu)
{
    case 0: editor_step_menu();     break;
    case 1: editor_step_tiles();    break;
}

if (menu_changed) room_goto(rooms[| cur_menu]);
Code:
/// @description Editor Room Changed
// You can write your code in this editor


switch(cur_menu)
{
    case 0: editor_init_menu();     break;
    case 1: editor_init_tiles();    break;
}
Code:
/// @description Item Create
// You can write your code in this editor

text_changed        = false;
timer_changed       = false;
index_changed       = false;
state_changed       = false;
image_start_changed = false;
image_end_changed   = false;

cur_text        = "";
cur_timer       = -1;
cur_index       = 0;
cur_state       = false;
cur_image_start = 0;
cur_image_end   = 0;

old_text        = cur_text;
old_timer       = cur_timer;
old_index       = cur_index
old_state       = cur_state;
old_image_start = cur_image_start;
old_image_end   = cur_image_end;

index     = 0;
parent    = noone;
item_exit = new_exit(0,0,0,0,0);
Code:
/// @description Item Step
// You can write your code in this editor

var input_a = keyboard_check_pressed(vk_enter);
var input_up = keyboard_check_pressed(vk_up);
var input_down = keyboard_check_pressed(vk_down);
var input_left = keyboard_check_pressed(vk_left);
var input_right = keyboard_check_pressed(vk_right);
 
var item_up    = item_exit[0];
var item_down  = item_exit[1];
var item_left  = item_exit[2];
var item_right = item_exit[3];


//Update changed status
text_changed        = false;
timer_changed       = false;
index_changed       = false;
state_changed       = false;
image_start_changed = false;
image_end_changed   = false;

if (cur_text        != old_text)         text_changed        = true;
if (cur_timer       != old_timer)        timer_changed       = true;
if (cur_index       != old_index)        index_changed       = true;
if (cur_state       != old_state)        state_changed       = true;
if (cur_image_start != old_image_start)  image_start_changed = true;
if (cur_image_end   != old_image_end)    image_end_changed   = true;

old_text        = cur_text
old_timer       = cur_timer
old_index       = cur_index
old_state       = cur_state
old_image_start = cur_image_start
old_image_end   = cur_image_end

if (cur_timer >= 0) cur_timer --;
if (image_index >= cur_image_end || image_index < cur_image_start) image_index = cur_image_start;

if (parent.cur_item == cur_index && parent.cur_item == parent.old_item)
{
   
    // Set timer when pressed
    if (input_a) cur_timer = 4;
   
    //Update pressed variable
    if (cur_state == true) cur_state = false;
    if (cur_timer == 0)    cur_state = true;

   

    //Handle index
    if (input_up)    parent.cur_item = item_up;
    if (input_down)  parent.cur_item = item_down;
    if (input_left)  parent.cur_item = item_left;
    if (input_right) parent.cur_item = item_right;
}
 
S

Shadowblitz16

Guest
ok so I think I got it
however I was wondering if there is a way to changed a variables when another variable updates?

so instead of having to do this..
Code:
/// @desc editor_step_menu()

//Menus
if (tools_menu.cur_state == 1) { cur_menu = 0; menu_changed = true; }


//Options
if (menu_tiles.cur_state == 1) { cur_menu = 1; menu_changed = true; }
I can just do this
Code:
/// @desc editor_step_menu()

//Menus
if (tools_menu.cur_state == 1) { cur_menu = 0; }


//Options
if (menu_tiles.cur_state == 1) { cur_menu = 1;  }
and update the menu_changed variables in the editor.step event.

Code:
if (cur_menu   != old_menu)   menu_changed   = true;
if (cur_item   != old_item)   item_changed   = true;
 
Top