SneakyBomber
SneakyBomber

Reputation: 21

GML room_goto() Error, Expecting Number

I'm trying to make a game that chooses a room from a pool of rooms using GML, but I get the following error:

FATAL ERROR in action number 3 of Create Event for object obj_control:

room_goto argument 1 incorrect type (5) expecting a Number (YYGI32) at gml_Object_obj_control_CreateEvent_3 (line 20) - room_goto(returnRoom)

pool = ds_list_create()

ds_list_insert(pool, 0, rm_roomOne)
ds_list_insert(pool, 1, rm_roomTwo)
ds_list_insert(pool, 2, rm_roomThree)
ds_list_insert(pool, 3, rm_roomFour)

var returnIndex;
var returnRoom;

returnIndex = irandom(ds_list_size(pool))
returnRoom = ds_list_find_value(pool, returnIndex)

if (ds_list_size(pool) == 0){
room_goto(rm_menu_screen)
}else{
room_goto(returnRoom)
}

I don't get the error message saying it's expecting a number.

Upvotes: 1

Views: 1120

Answers (1)

Rob
Rob

Reputation: 4987

This is weird indeed... I think this should actually work.. But I have no GM around to test :(

For now you can also solve this using "choose". This saves a list (and saves memory, because you're not cleaning up the list by deleting it - thus it resides in memory)

room_goto(choose(rm_roomOne, rm_roomTwo, rm_roomThree, rm_roomFour));

choose basically does exactly what you're looking for. Might not be the best way to go if you're re-using the group of items though.

Upvotes: 0

Related Questions