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

Elevator with single switch for up and down

Recommended Posts

I'm having problem making an elevator. The elevator has multiple sectors moving with it, so I've written a script to lower all the floors and ceilings by the same amount. Everything works going one direction - the difficulty comes because I want to control the elevator with the same switch. I know how to make a switch that has two different functions, but I can't figure out how to make it so that the switch only works when the elevator isn't moving. This is important because if the player uses the switch multiple times while the elevator is moving it'll execute a move in an alternate direction by the fixed amount in the script and will end up not on a proper floor.

Picture of the lift - http://imgur.com/oOVqjqJ

The script I've written thus far:

int a = 1;

Script 11 (void)

{
if (a == 1) // Top Floor
{
	Floor_LowerByValue (1, 8, 564);
	Ceiling_LowerByValue (1, 8, 564);
	Delay (140);
	a = 2;
}

	else if (a == 2) // Bottom Floor

{
	Floor_RaiseByValue (1, 8, 564);
	Ceiling_RaiseByValue (1, 8, 564);
	Delay (140);
	a = 1;
}
}
I put the delay in because I thought perhaps I could just time it so that "a" doesn't change value until the lift has finished moving, but there must be a better way of doing it. I've looked around on the zdoom wiki trying to find how to do it but don't know where to look. Can anyone help?

Share this post


Link to post

Use TagWait to make the script wait until the sector has stopped moving. If you are using ACS_Execute (80), then the script will be locked until TagWait finishes.

Share this post


Link to post
Quineotio said:

I'm having problem making an elevator. The elevator has multiple sectors moving with it, so I've written a script to lower all the floors and ceilings by the same amount. Everything works going one direction - the difficulty comes because I want to control the elevator with the same switch. I know how to make a switch that has two different functions, but I can't figure out how to make it so that the switch only works when the elevator isn't moving. This is important because if the player uses the switch multiple times while the elevator is moving it'll execute a move in an alternate direction by the fixed amount in the script and will end up not on a proper floor.

Picture of the lift - http://imgur.com/oOVqjqJ

The script I've written thus far:

int a = 1;

Script 11 (void)

{
if (a == 1) // Top Floor
{
	Floor_LowerByValue (1, 8, 564);
	Ceiling_LowerByValue (1, 8, 564);
	Delay (140);
	a = 2;
}

	else if (a == 2) // Bottom Floor

{
	Floor_RaiseByValue (1, 8, 564);
	Ceiling_RaiseByValue (1, 8, 564);
	Delay (140);
	a = 1;
}
}
I put the delay in because I thought perhaps I could just time it so that "a" doesn't change value until the lift has finished moving, but there must be a better way of doing it. I've looked around on the zdoom wiki trying to find how to do it but don't know where to look. Can anyone help?


In this code. Int is an integer, right? You've named it, "a" but it could just as well be, "Elevator"?

Why are you saying that a = 1? Is that off? You've used 1 and 2. Why not 1 and 0?

so a = 1 means that the elevator is off? It's at the top floor by default?

or is a the switch?

Is this executed through action 80?

Edit: Sorry for all the questions.

Share this post


Link to post

No problem.

Yes I've name it "a" but it could be "elevator".

I've used 1 and 2 instead of 1 and 0 for no particular reason - perhaps they're just easier numbers for me.

The script is executed when you click the switch (Tagdef 80 - repeatable action when clicked on), which is inside the elevator and can be use at both the top and bottom floor. What the script does is if a = 1, at the same time lower the ceiling and the floor of sectors tagged "1" by 564 units at speed 8, then change to a = 2. Else when a = 2 raise the ceiling and floor... and change "a" back to "1".

I hope this is what you wanted to know. I'm new to scripting so this script is probably not the most elegant script ever written.

I've actually worked on the elevator since then. If you're interested:


Script 11 (void)

{
	if (a == 1)
{
	Floor_RaiseByValue (47, 14, 30);
	Floor_RaiseByValue (44, 17, 39);
	Ceiling_LowerByValue (47, 14, 30);
	Ceiling_LowerByValue (44, 17, 39);
	TagWait (44);
	Delay (35);
	Floor_LowerByValue (1, 12, 564);
	Ceiling_LowerByValue (1, 12, 564);
	TagWait (1);
	Delay (35);
	Floor_LowerByValue (46, 14, 30);
	Floor_LowerByValue (45, 17, 39);
	Ceiling_RaiseByValue (46, 14, 30);
	Ceiling_RaiseByValue (45, 17, 39);
	TagWait (45);
	a = 2;
}

	else if (a == 2)

{
	Floor_RaiseByValue (46, 14, 30);
	Floor_RaiseByValue (45, 17, 39);
	Ceiling_LowerByValue (46, 14, 30);
	Ceiling_LowerByValue (45, 17, 39);
	TagWait (45);
	Delay (35);
	Floor_RaiseByValue (1, 12, 564);
	Ceiling_RaiseByValue (1, 12, 564);
	TagWait (1);
	Delay (35);
	Floor_LowerByValue (47, 14, 30);
	Floor_LowerByValue (44, 17, 39);
	Ceiling_RaiseByValue (47, 14, 30);
	Ceiling_RaiseByValue (44, 17, 39);
	TagWait (44);
	a = 1;
}
}

What I've essentially done is make doors to the lift, which you can see in the picture. The doorway you enter the lift (tagged 47 for the main bit and 44 for the "teeth") close around you when you click the switch, then the other, "open" side's doors (tags 45 and 46) open and let you out at the bottom. Note that I've given the doors (tags 44, 45, 46 and 47) a second tag of "1" so that they move with the rest of the elevator.

If you have any more questions please ask :)

Share this post


Link to post

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
×