GameMaker Studio 2 Desktop

GameMaker Studio 2 Desktop

Problem with "room_goto"
I have a problem with my rooms.

Room 1 - a start menu with a button to jump to Room 2
Room 2 - the game

If I only run Room 2, or put it ahead of Room 1 in the resource tree, it works as expected. However, if Room 1 is the first room then I get this error after jumping to Room 2:

Variable references invalid object

Why would Room 2 only throw this error after the room_goto action in Room 1, and not when run independently. Is it something to do with persitence? Or is Room 1 not finished before Room 2 starts? I'm very confused. Anyway, here's the actual code:

ROOM 1 START MENU
switch (mpos) { case 0: room_goto(rm_board); // rm_board is Room 2 break; case 1: room_goto(rm_options); break; case 2: game_end(); break; default: break; }

ROOM 2 - which contains a "controller" object with this Create event:

globalvar grid; grid = instance_create_layer(0, 0, rm_board, obj_grid); // grid object grid.xs = 60; grid.ys = 30;

ERROR

FATAL ERROR in action number 1 of Create Event for object obj_controller: Pop :: Execution Error - Variable references invalid object (-4).<unknown variable> at gml_Object_obj_controller_Create_0 (line 14) - grid.xs = 60;

Any help is much appreciated.

最近の変更はJapanGamer29が行いました; 2017年4月14日 18時41分
< >
1-3 / 3 のコメントを表示
Thew 2017年4月14日 20時23分 
The issue is you're passing a resource name (a room) to the instance_create_layer() function. It's looking for a layer ID, typically in quotes.
instance_create_layer(0, 0, "Layer_Name", obj_grid);

Here's the function reference from the manual:
https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/instances/instance_functions/instance_create_layer.html

Hopefully this will fix your problem!
最近の変更はThewが行いました; 2017年4月14日 22時40分
The only thing I see is your controller create event line: grid = instance_create_layer(0, 0, rm_board, obj_grid);

Shouldn't the "rm_board" be a layer - something like "Instances" with the quotes included? (if you really meant to use "instance_create_layer" instead of something like mp_grid_create - unless that is created in your obj_grid object.)

Edit - oops, Thew got you already.
最近の変更はWardiaperが行いました; 2017年4月14日 20時37分
Brilliant! That was it. Thank you both very much. :-)
< >
1-3 / 3 のコメントを表示
ページ毎: 1530 50

投稿日: 2017年4月14日 18時40分
投稿数: 3