Jump to content
Search In
• More options...
Find results that contain...
Find results in...

# Randomly lower a platform (or eight)

## Recommended Posts

Hi,

I would like to have the player walk over a linedef that triggers an ACS script (D-in-H format). The script will ideally lower a random platform, delay for about 20 seconds and then lower another random platform and so on until all eight platforms have been lowered. While I can do simple scripts, I can't work out how I would be able to do this?

Would anyone be able to provide an example please.

Thanks,

Dave

#### Share this post

##### Link to post

Something like this should work.

```script "Platform Sequence" ()
{
int i;
int platforms[8] == { 1, 2, 3, 4, 5, 6, 7, 8 };
for (i = 0; i < 8; ++i)
{
int j = random(i, 7);
int platform = platforms[j];
platforms[j] = platforms[i];
Floor_LowerToLowest(platform, 32); // or Floor_LowerByValue or whatever
delay(20*35);
}
}```
The platforms array (note the plural) contains the TIDs of the eight different platforms. In this example, they are 1 to 8, but they could be anything else.

The script will loop eight times. Each time, it'll pick a random number between the iteration (so, 0 the first time, 1 the second, 2 the third, etc. until 7 on the eighth) and 7. The TID from the array at that index is chosen as being our random platform for this iteration.

Then the value in the array is replaced by one that hasn't been used yet. (Though it might happen that it gets replaced by itself if the minimum was rolled. Not a problem.) The loop waits for twenty second. This way, we make sure that a same platform will not be randomly chosen twice.

#### Share this post

##### Link to post

Cheers Gez,

You really rather good at all this :)
My ideas outweight my skills atm. I am learning and I'll get there eventually!!

Dave

#### Share this post

##### Link to post

Hi Gez,

A couple of problems with the script...

```script "Platform Sequence" ()
```
DB2 gives an error regarding the script number or lack of, so adding one in,
```script 2 "Platform Sequence" ()
```
also errors with bad script declaration. If i change it to read,
```script 2 (void)
```
does compile further but errors at this point;
```int platforms[8] == { 9, 10, 11, 12, 13, 14, 15, 16 };
```
gives the errors,
1 Only map variables can be arrays
2 Invalid identifier

Any suggestions??

Cheers,

Dave

#### Share this post

##### Link to post

I'm pretty sure arrays have to be global. So declare the array outside any script. Also I think just a simple mistake:
=
instead of
==
in that case (former is assignment operator, last means equals

#### Share this post

##### Link to post
gggmork said:

I'm pretty sure arrays have to be global. So declare the array outside any script. Also I think just a simple mistake:
=
instead of
==
in that case (former is assignment operator, last means equals

Ok,

So I would take the following;

`	int platforms[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };`
and stick it after the #include line.

I'll give it a whirl in the morning as I'm off to bed now!

Thanks for all the help and the patience,

Dave

#### Share this post

##### Link to post
Phendrena said:

Hi Gez,

A couple of problems with the script...

```script "Platform Sequence" ()
```

I gave you a named script for the example. If you haven't updated the ACC from the one that was provided with DB2, it's not going to work. Just replace the name with a number then.

For the other two things, gggmork is correct.

#### Share this post

##### Link to post

It is all working rather nicely now and will (hopefully) be quite a nasty surprise!!

Thank you all for you help :)

Dave

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now
×