1

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.

Community
  • 1
  • 1

1 Answers1

0

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.

Rob
  • 4,927
  • 4
  • 26
  • 41
  • Thank you for your reply. Apparently choose returns the same value when you restart the game however? – SneakyBomber Jun 03 '16 at 20:11
  • Ok, for some reason it works now though I'm running into some other problem. I'll post that in a new question. Again, thanks for your help! choose() itself is working like a charm! – SneakyBomber Jun 04 '16 at 06:28
  • Yes, choose() uses the random functions, Just like irandom() would return the same value every time the game restarts as well. This has got something to do with the "random seed". Check out the random functions in the docs, they explain it perfectly and it states how you can randomize the seed with a specific function to get random events every time. – Rob Jun 04 '16 at 11:21
  • @SneakyBomber you can mark this question as answered if it is? :) – Rob Jun 04 '19 at 14:04