User Profile | Member List | F.A.Q | Privacy Policy | New Blog | Search Forums | Forums Home
 Doomworld Forums > Classic Doom > Doom Editing > Randomly lower a platform (or eight)
Author
 All times are GMT. The time now is 13:51.
Phendrena
Junior Member

Posts: 188
Registered: 09-12

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

Oct 15 2012 11:23 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
Gez
Why don't I have a custom title by now?!

Posts: 12389
Registered: 07-07

Something like this should work.
```code: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.

Oct 15 2012 13:16 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
Phendrena
Junior Member

Posts: 188
Registered: 09-12

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

Oct 15 2012 14:41 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
Phendrena
Junior Member

Posts: 188
Registered: 09-12

Hi Gez,

A couple of problems with the script...
```code:script "Platform Sequence" ()
```
DB2 gives an error regarding the script number or lack of, so adding one in,
```code:script 2 "Platform Sequence" ()
```
also errors with bad script declaration. If i change it to read,
```code:script 2 (void)
```
does compile further but errors at this point;
```code: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

Oct 15 2012 21:46 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
gggmork
If you can make any sense of this post, congratulations

Posts: 2862
Registered: 06-07

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

Oct 15 2012 23:01 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
Phendrena
Junior Member

Posts: 188
Registered: 09-12

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:
=
==
in that case (former is assignment operator, last means equals

Ok,

So I would take the following;
`code:	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

Oct 15 2012 23:48 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
Gez
Why don't I have a custom title by now?!

Posts: 12389
Registered: 07-07

Phendrena said:
Hi Gez,

A couple of problems with the script...
```code: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.

Oct 15 2012 23:53 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
Phendrena
Junior Member

Posts: 188
Registered: 09-12

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

Thank you all for you help :)

Dave

Oct 16 2012 09:46 #
 || Blog || PM || Post History || Add Buddy IP || Edit || Quote
 All times are GMT. The time now is 13:51.
 Doomworld Forums > Classic Doom > Doom Editing > Randomly lower a platform (or eight)

Forum Rules:
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is OFF vB code is ON Smilies are OFF [IMG] code is ON