Search In
• More options...
Find results that contain...
Find results in...
• 0

# Making a script choose between different actions/tags at random?

## Question

Let's say that I have 3 doors, and that I want only one of them to open when a player crosses a linedef or presses a switch. Is there any way to make it so that when the linedef is crossed or the switch is pressed that a script fires so that any of the 3 doors could open but only one actually does basically at random?

## Recommended Posts

• 2

To elaborate on the other answer, you'd do something like this, where the two numbers in Random are the range of tags of the sectors for the doors.

```int doorTag = 0;
doorTag = Random(5, 7);```

This will give you either tag 5, 6, or 7. If your door tags are not in a range like this and are spread out, you will need to either re-tag them to be in order or do something like this:

```int doorTags[3] = {5, 13, 24};
int doorToOpen = 0;

doorToOpen = doorTags[Random(0,2)];```

I'm not sure if the above will work though.

EDIT: It will work now.

Edited by Nevander

• 0

Yes, use Random in the script.

• 0
23 minutes ago, Nevander said:

If your door tags are not in a range like this and are spread out, you will need to either re-tag them to be in order or do something like this:

```
int doorTags[3] = {5, 13, 24};
int doorToOpen = 0;

doorToOpen = Random(doorTags[0], doorTags[2]);```

I'm not sure if the above will work though.

It would not work as intended, such a code would return any integer between 5 and 24 rather than just the values in the array. But this would work the way you meant it:

```int doorTags[3] = {5, 13, 24};
int doorToOpen = 0;

doorToOpen = doorTags[Random(0,2)];```

Edited by scifista42

• 0
1 hour ago, scifista42 said:

It would not work as intended, such a code would return any integer between 5 and 24 rather than just the values in the array. But this would work the way you meant it:

Yep that's what I was going for. Thanks for fixing it, I wasn't sure mine was right but I knew you could do a random range value using an array.