Random Room Movement

Alf
14 Mar 2008, 19:45
Hi Y'all.

Is there a way to move the player to a random room? Example: The overdrinker, totally zonked and staggering through the house. May end up in ANY room in the house. In this case, a totally random room.

How about have the player end up in a random room from a predefined set of rooms. Example: The overdrinker, slightly tipsy, may stagger into the wrong bedroom. In this case, a random event with only two or three outcomes.

I've seen some posts regarding random events, but I want to move my user to a random room.

Thanks in advance!

Elexxorine
14 Mar 2008, 21:56
Create any array with the values as the names of the rooms you want the person to be able to end up in. Then have a random value between 1 and the upper bound of the array. Then move the player to the value of the array with index of the random value.

Hope you understand what I mean. If you want asl, I can make it. I can't do QDK.

I think Im Dead
16 Mar 2008, 02:01
The above is correct, an array, then simply choosing a random number within the array to move the player to would be the best way, however in execution there seems to be a bit of difficulty. Typically you would simply give each room in your game a room property, and the code would work like this...

set numeric <n; 0>
for each object in game if property <#quest.thing#; room> then {
inc <n>
set string <room[n]; #quest.thing#>
}
set numeric <x; $rand(1;%n%)$>
goto <#room[x]#>

However it appears in the newest iteration of Quest, the FOR EACH OBJECT IN GAME code, no longer goes through rooms, so we are effectively left without a way to search rooms for qualifiers. I suspect this is an oversight and a bug on Alex's part. I'm thinking up an automated work around but it will be a little tricky.

There is still the option of doing this manually though, which just means coding the array by hand, which is still pretty simple. You'll just put each room of the house into an array called house, then wrap that in a command or conditional or however you want to use it.

command <stagger> {
set string <house[1]; login>
set string <house[2]; logout>
set string <house[3]; other room>
set numeric <n; $rand(1;3)$>
msg <You stagger about drunken.>
goto <#house[n]#>
}

Alex
16 Mar 2008, 11:16
I'm not sure that code would ever have worked - it doesn't iterate through rooms in Quest 3.53 either.

One messy way you could do it is to assume you have objects in each room. Then iterate through objects, and if the parent room is not already in the array then add it.

I'll add "for each room in game" to the "to do" list.

Alf
17 Mar 2008, 11:51
Many thanks for all the replies.

A unique room identifier would be great, Alex.

How about a tag? If you gave each room (or at least the ones you wanted to address) a tag and a numeric value for the tag, could you then iterate through the set? Just a thought...


Thanks again!

METALGod32
26 Mar 2008, 04:08
one way is to set up a $rand(lowest number; highest number)$, followed by a if statement, example.

if it is like: $rand(1; 12)$ for example and it falls on 4 for example, the IF statement will say where
the player goes to if it is 4.

Put the entire code into a proc, so you can simply refer to the proc wrather then
typing the entire code many times.

Alf
31 Mar 2008, 11:27
Thanks for the reply.

What number is in the $rand statement?

METALGod32
31 Mar 2008, 20:42
It'll be like this: $rand(1, 2)$, so 1 is the lowest number of your choosing and 2 will be the highest.
so if there is even 100 posible rooms to randomly go to you'd do this: $rand(1, 100)$, followed by an if statement.
there is other ways to do it to, this is just one way.

remember in $rand(LOW NUMBER, HIGH NUMBER)$ you choose the highest and lowest number.

$rand(low, high)$ will be stored in a num var of your choosing, you then compare this var with
a number in the IF statement.