Using single switch to go up/down in elevator?

Discuss all aspects of editing for ZDoom.
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Using single switch to go up/down in elevator?

Postby ReX » Tue Mar 27, 2012 2:36 pm

I want to be able to control a script to ride up or down an elevator using a single switch. In other words, if I want to ride the elevator up I would press the top part of the switch, and if I want to ride down I'd press the bottom part. Is there a way for the game to identify where the switch is being pressed, and activate the proper part of the script?

Here is a picture of the switch texture:

xswit16a.png
Switch with up/down arrows
xswit16a.png (2.91 KiB) Viewed 247 times
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace

Re: Using single switch to go up/down in elevator?

Postby NeuralStunner » Tue Mar 27, 2012 2:39 pm

You could check the height of the elevator's floor, and take the appropriate action. This would also have the advantage of preventing the buttons from working while in transit.

I think you'd need SetLineTexture to assign the proper lit-up image to the button. Alternatively, change its texture and special at the same time!
User avatar
NeuralStunner
O'Neill with it.
 
Joined: 21 Jul 2009
Location: The Colonies

Re: Using single switch to go up/down in elevator?

Postby ReX » Tue Mar 27, 2012 3:03 pm

NeuralStunner wrote:You could check the height of the elevator's floor, and take the appropriate action. This would also have the advantage of preventing the buttons from working while in transit.

Actually, I've set up a script that check the player's height against the floor height to let the game know when to lower the elevator (i.e., if it is on a higher floor), and when to raise it (i.e., if it's on a lower floor). This works perfectly when the player is outside, and calling the elevator to his/her floor, and it does not require an up/down selection. But, obviously, this does not work on the switch inside the elevator.

When I'm inside the elevator, how do I check where on the switch the player has pressed "use", so the script will know if the elevator needs to go up or down?

I think you'd need SetLineTexture to assign the proper lit-up image to the button. Alternatively, change its texture and special at the same time!

This part I've taken care of.
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace

Re: Using single switch to go up/down in elevator?

Postby Phobus » Tue Mar 27, 2012 3:07 pm

The way you're describing it ReX, no, not really.

What you could do is fake it if there's only two floors (but I imagine you know that) and the alternatives would be to either fake it by using that texture across two sectors (the front one and a 1 pixel-width one to house the top/bottom one) and hoping to hell the two lines don't interfere with eachother when pressing use "through" one to the other OR you could make a selection script a bit like solarsnowfall once did to make a keypad that could be typed on much like the interfaces in Doom 3.
User avatar
Phobus
 
Joined: 05 May 2005
Location: Histon, Cambridge

Re: Using single switch to go up/down in elevator?

Postby LilWhiteMouse » Tue Mar 27, 2012 3:22 pm

If the switch could be placed at the proper height, you could check the player's pitch to see if they were looking up or down when activated.
User avatar
LilWhiteMouse
"Stop the world, I'm getting off."
 
Joined: 15 Jul 2003
Location: Maine, US

Re: Using single switch to go up/down in elevator?

Postby ReX » Tue Mar 27, 2012 5:37 pm

LilWhiteMouse wrote:If the switch could be placed at the proper height, you could check the player's pitch to see if they were looking up or down when activated.

That works nicely, thanks. I have succeeded in using a single switch to take an elevator up or down, depending on where on the switch the player presses "use". The code is shown below. However, I am running into two problems:

1. Once the elevator has reached the appropriate floor, I can activate the switch to raise/lower the elevator before the sliding doors shut. This means that the doors remain open while the elevator is in motion. [Aside from not being "realistic", this can cause problems if the player steps into the doorway and blocks the moving floors.] How do I "immobilize" the switch until the doors have shut?
2. Once I enter the elevator and the doors have shut behind me, I cannot exit through those doors again onto the floor I entered from. I have to go up or down for the doors to open. A work-around is to make the polyobjects activate the door, so that I can "use" the doors to open them. [And once Item 1, above, is solved, this is a viable solution.] Is there any other way to achieve this? I tried using GetActorPitch (0) = 0, but there was a syntax error, and I commented it out (see below).

Spoiler:
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace

Re: Using single switch to go up/down in elevator?

Postby Gez » Tue Mar 27, 2012 6:11 pm

ReX wrote:Is there a way for the game to identify where the switch is being pressed, and activate the proper part of the script?

There is a way to force a height check on the switch, and it is when the switch is placed on a 3D middle texture. But then you have to use two different linedefs for the switch.
Gez
 
Joined: 06 Jul 2007

Re: Using single switch to go up/down in elevator?

Postby Blzut3 » Tue Mar 27, 2012 10:03 pm

ReX wrote:1. Once the elevator has reached the appropriate floor, I can activate the switch to raise/lower the elevator before the sliding doors shut. This means that the doors remain open while the elevator is in motion. [Aside from not being "realistic", this can cause problems if the player steps into the doorway and blocks the moving floors.] How do I "immobilize" the switch until the doors have shut?

PolyWait
Rez wrote:2. Once I enter the elevator and the doors have shut behind me, I cannot exit through those doors again onto the floor I entered from. I have to go up or down for the doors to open. A work-around is to make the polyobjects activate the door, so that I can "use" the doors to open them. [And once Item 1, above, is solved, this is a viable solution.] Is there any other way to achieve this? I tried using GetActorPitch (0) = 0, but there was a syntax error, and I commented it out (see below).

You're looking for == the comparison operator not = the assignment operator.
Blzut3
Pronounced: B-l-zut
 
Joined: 24 Nov 2004

Re: Using single switch to go up/down in elevator?

Postby Isle » Tue Mar 27, 2012 10:40 pm

having to hit exactly 0 pitch would make it too hard to use. I'd just put another open door switch next to it. though you could do them in a row but it would take a bit more math.
User avatar
Isle
WadAuthor 4 L1F3
 
Joined: 21 Nov 2003
Location: Arizona, USA

Re: Using single switch to go up/down in elevator?

Postby ReX » Wed Mar 28, 2012 7:20 am

Phobus wrote:...you could make a selection script a bit like solarsnowfall once did to make a keypad that could be typed on much like the interfaces in Doom 3.

I have seen the keypad example by Isle, which is a terrific application, but far too complex for my needs, methinks. Perhaps you were thinking of solarsnowfall's DooM card game with a similar principle?

Gez wrote:There is a way to force a height check on the switch, and it is when the switch is placed on a 3D middle texture. But then you have to use two different linedefs for the switch.

Although I've already solved my problem using LWM's suggestion, would you point me to an example of such a height check? I know how to do a player's height check, but not one where the crosshair's height is checked.

Blzut3 wrote:Polywait

Yes, this is what I was looking for. [I figured there was some polyobject equivalent of TagWait.] Thanks.

Blzut3 wrote:You're looking for == the comparison operator not = the assignment operator.

Isle wrote:having to hit exactly 0 pitch would make it too hard to use. I'd just put another open door switch next to it. though you could do them in a row but it would take a bit more math.

Blzut3, thanks for the clarification.
Isle, you're correct about the difficulty of hitting 0 pitch exactly. In the dozens of times I've tested the switch I've gotten it right only once. I think that the simplest way to do it is to use PolyWait to prevent the switch in the elevator from being used until the doors have closed, and allow the player to use the doors to open them.

Two additional questions:
1. Using PolyWait I can immobilize either the switch in the elevator or the one on the floor (outside the elevator door). How do I immobilize the switch outside until the doors, when opened using the switch inside the elevator, have closed (and vice versa)?
2. If I open the doors (use the polyobject) from inside the elevator, how do I immobilize the switches until the doors have closed?

Perhaps I can put PolyWait at the top of each script, and solve both problems? (I'm off to give it a shot.)

EDIT: I just tested the scripts with PolyWait at the top & bottom of each segment of my scripts, and it works flawlessly.
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace

Re: Using single switch to go up/down in elevator?

Postby Gez » Wed Mar 28, 2012 7:52 am

ReX wrote:Although I've already solved my problem using LWM's suggestion, would you point me to an example of such a height check?

Verification done, it only checks if the player is logically able to activate the switch; so it doesn't help in your situation where the player is able to activate both switches.
Gez
 
Joined: 06 Jul 2007

Re: Using single switch to go up/down in elevator?

Postby Blzut3 » Wed Mar 28, 2012 5:12 pm

ReX wrote:Isle, you're correct about the difficulty of hitting 0 pitch exactly. In the dozens of times I've tested the switch I've gotten it right only once.

That said, hitting exactly 0 is extremely easy for someone not using freelook. I'm sure your mod would be broken with no freelook in many other places so the point may be invalid, but I would suggest using that condition for a default case. (Iterate through floors is probably the most logical.)

Also you probably want to use scriptwait if you want to check if another script is done executing.
Blzut3
Pronounced: B-l-zut
 
Joined: 24 Nov 2004

Re: Using single switch to go up/down in elevator?

Postby ReX » Wed Mar 28, 2012 9:49 pm

Blzut3 wrote:That said, hitting exactly 0 is extremely easy for someone not using freelook. I'm sure your mod would be broken with no freelook in many other places so the point may be invalid, but I would suggest using that condition for a default case. (Iterate through floors is probably the most logical.)

Agreed on the point about freelook. What did you mean about the "default case"? Is that not what I've done in my script (i.e., pitch == 0)? Also, what did you mean about iterating through floors? [I.e., what's its connection with using the upper part vs the lower part of the switch?]

Also you probably want to use scriptwait if you want to check if another script is done executing.

ScriptWait. One more thing I've learned. Thanks. [Although, in my case the closing of the elevator doors corresponds to the end of the relevant section of each script, so PolyWait works just as well.]
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace

Re: Using single switch to go up/down in elevator?

Postby Blzut3 » Wed Mar 28, 2012 10:10 pm

ReX wrote:Agreed on the point about freelook. What did you mean about the "default case"? Is that not what I've done in my script (i.e., pitch == 0)? Also, what did you mean about iterating through floors? [I.e., what's its connection with using the upper part vs the lower part of the switch?]

Basically something like this pseudocode:
Code: Select allExpand view
int liftDirection = 1; // Start by going up
script 4 (void)
{
    if(upbutton pressed) {
        liftDirection = 1;
        // up button code
    }
    else if(downbutton pressed) {
        liftDirection = -1;
        // down button code
    }
    else
    {
        if(liftDirection > 0)
        {
            LiftFloor++;
            if(LiftFloor >= 3) // When we hit the top floor change directions
                liftDirection = -1;
        }
        else
        {
            LiftFloor--;
            if(LiftFloor <= 0) // When we hit the bottom change directions
                liftDirection = 1;
        }
    }
}

That should give you the general idea. Someone without freelook would stop at every floor going up and then start going down one floor at a time. Once the bottom is reached start going up again.
Blzut3
Pronounced: B-l-zut
 
Joined: 24 Nov 2004

Re: Using single switch to go up/down in elevator?

Postby MG_Man » Sun Apr 01, 2012 12:02 pm

Instead of just looking for having the pitch equal zero, it would be better to define a range of pitch that would fit the full range of each button. So, I suggest having the script print your pitch on the screen, and write down your pitch when you are looking at the top of the top button, bottom of the top button, etc. The problem is it would vary depending on how far away you are from the switch, so you might have to do some trig to make it adjust.
User avatar
MG_Man
TarviS
 
Joined: 28 Jul 2007


Return to Editing

Who is online

Users browsing this forum: Google [Bot], Xeotroid and 1 guest