Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075932 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:14:09 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Go to a random room?
Pages: [1]
Print
Author Topic: Go to a random room?  (Read 397 times)
Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« on: August 05, 2013, 08:19:21 AM »

Looking for a way to go to a random room when you reach an exit. I also need to mark the room you left as completed and never return to that room again.

I'm not sure how to find the room index, or figure out how they are stored. I assume I'd just take the room index, add or subtract a random number to it, and then go to the room with the matching index? I'm not sure how, or if you can, set variables for individual rooms.
Logged

Ant
Guest
« Reply #1 on: August 05, 2013, 08:40:00 AM »

I had to do this for one of my games. I stored the room name and completion variables in an array then just kept randomly choosing a room until it found one that hadn't been completed.

So first you'll need to fill out the array with the room names and initialise the completion variables.

Code:
global.vRoom[0,0] = rRoomName1;
global.vRoom[0,1] = 0;
global.vRoom[1,0] = rRoomName2;
global.vRoom[1,1] = 0;

global.vNumberOfRooms = 2;

Then to pick an uncompleted room do something like this:

Code:
while true
{
  var i = irandom(global.vNumberOfRooms);
  if global.vRoom[i,1] = 0 {room_goto(global.vRoom[i,0]); break;}
}

Then when you complete a room you'll need to update the array, best way of doing this automatically is via a loop of some kind that runs through the array and once it finds the room that corresponds with the current room it marks it as complete. Something like:

Code:
for (i=0; i<global.vNumberOfRooms; i++)
{
  if room = global.vRoom[i,0] {global.vRoom[i,1] = 1; break;}
}
Logged
Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #2 on: August 05, 2013, 08:41:32 AM »

Is this gonna work with 100 rooms? I also though GM didn't have arrays... :l
Logged

Ant
Guest
« Reply #3 on: August 05, 2013, 08:44:40 AM »

Yeah GM can do 1d and 2d arrays and yeah it'll work for any number of rooms. It would take a while to manually write up an array for all those rooms though, there's probably an easy way of automatically inputting all the rooms, not sure how though.
Logged
Zack Bell
Level 10
*****



View Profile WWW
« Reply #4 on: August 05, 2013, 08:51:14 AM »

I believe that you can use room_first to find the ID of the first room, then loop through the rooms until you hit room_last. You could add these indexes to a ds_list or an array in a simple for loop.

If you use a list, you could just shuffle the list instead and grab the first element.

Plenty of ways to do it Smiley

Heck, you could do choose(list 100 room names) hahaha
Logged

Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #5 on: August 05, 2013, 08:54:21 AM »

I was under the impression that choose only held 16 arguments.
Logged

Polly
Level 4
****


View Profile
« Reply #6 on: August 05, 2013, 08:56:50 AM »

I'd create a list to store all the rooms indices in. For "static" rooms ( rooms that haven't been created dynamically ) you can do something like this to populate the list ..

Code:
room_list = ds_list_create();
i = room_first;

while(i != -1)
{
    ds_list_add(room_list, i);
    i = room_next(i);
}

.. and then to select a random room ( and remove it from the list ) something like ..

Code:
p = random(ds_list_size(room_list));
i = ds_list_find_value(room_list, p);
ds_list_delete(room_list, p);
room_goto(i);
Logged
Zack Bell
Level 10
*****



View Profile WWW
« Reply #7 on: August 05, 2013, 08:59:13 AM »

Choose(choose(1,2,3), choose(4,5,6), choose(choose(7,8), 9, 10));

You see where I'm going... Don't do that though lol. Polly just posted the method that I was alluding to previously.
Logged

Rat Casket
Level 10
*****


i can do what i want

TheRabbitInferno
View Profile WWW Email
« Reply #8 on: August 05, 2013, 09:01:13 AM »

Okay cool. I think I understand whats going on... real programming is hard.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic