Switch/Case Block

Advanced OpenGL source port fork from ZDoom, picking up where ZDoomGL left off.
[Home] [Download] [Git builds (Win)] [Git builds (Mac)] [Wiki] [Repo] [Bugs&Suggestions]

Moderator: Graf Zahl

Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Switch/Case Block

Post by Bob Evans »

Using GZDOON (UDMF)
This has most likely been done already I'm sure. There is a floor at "0" height and needs to be move to "128" and vice versa via one switch.
The one switch basically has 3 modes:
1- floor position at "128" and moves to "0".
2- floor position at "0" and moves to "128".
3- floor in transition (value is changing) between the 2 heights.
From what I read this should be possible with Switch/Case Block via Script however how do I get the variable floor height value as the "x"
into the script. There should be 3 case blocks I think as I mentioned above. Unless there is another way I am unaware of.
A "search" came up empty.
User avatar
Gez
Developer
Developer
Posts: 1399
Joined: Mon Oct 22, 2007 16:47

Re: Switch/Case Block

Post by Gez »

[wiki]GetSectorFloorZ[/wiki]
User avatar
Enjay
Developer
Developer
Posts: 4751
Joined: Tue Aug 30, 2005 23:19
Location: Scotland

Re: Switch/Case Block

Post by Enjay »

Unless I'm missing something, what you want to do is flip a switch, have the floor move to the other height (move to 128 if it is at 0 or move to 0 if it is at 128) and have the switch do nothing if the floor is in transit.

If that's the case, I would do it like this:

Have a variable that is 0 or 1 depending on which level the floor is at (say 0 if the floor is at 0 and 1 if it is at 128).
Have the switch run the script that checks the variable and using "if" executes a block of code that moves the floor to the appropriate height and changes the variable.

Within the blocks of code, I would use the [zwiki]TagWait[/zwiki] ACS command that will pause the script until the floor has finished moving. This means the script will be running for the duration of the move and so, if you use [zwiki]ACS_Execute[/zwiki] (line type 80) to start the script, a second copy of the script cannot be run if one is already running, so a second copy of the script cannot be run while the floor is moving.

Something like this:

Code: Select all

int floorheight;

script 1 (void)
{
if (floorheight == 0)
	{
	Floor_RaiseByValue (tag, speed, 128);
	tagwait(tag);
	floorheight=1;
	terminate;
	}
	
if (floorheight == 1)
	{
	Floor_LowerByValue (tag, speed, 128)
	tagwait(tag);
	floorheight=0;
	terminate;
	}
}
Using the above method would only require 1 variable and two blocks of code (one to raise the floor and set the variable to 1 and one to lower it and set the variable to 0) and it would not require an "intermediate" block of code for if the lift was in motion. Perhaps this doesn't suit your needs but it's what I would do from my understanding of the intention.
Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Re: Switch/Case Block

Post by Bob Evans »

Gez: Thanks. That was what I could not locate for some reason.
Enjay: You are correct on the switch. Sorry if I wasn't clear enough. I had previously looked at ACS_Execute but was unaware of TagWait.
I will give it a go tonight. Thanks.
User avatar
Enjay
Developer
Developer
Posts: 4751
Joined: Tue Aug 30, 2005 23:19
Location: Scotland

Re: Switch/Case Block

Post by Enjay »

I don't know if it is really needed or not but I usually add a short "delay" command (8 tics or so) after the variable has changed just as a "belt and braces approach" to ensure that the script cannot be run until everything important from the previous instance has definitely been executed.

Presumably you could combine what I suggested with GetSectorFloorZ and use the GetSectorFloorZ value instead of the variable if you wanted.
Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Re: Switch/Case Block

Post by Bob Evans »

Enjay wrote:I don't know if it is really needed or not but I usually add a short "delay" command (8 tics or so) after the variable has changed just as a "belt and braces approach" to ensure that the script cannot be run until everything important from the previous instance has definitely been executed.

Presumably you could combine what I suggested with GetSectorFloorZ and use the GetSectorFloorZ value instead of the variable if you wanted.
I added the DELAY as a safety. Went overboard again and added 4 sectors on the floor and everything works. Thank you. :)

Ended up changing things a bit. Added Sector_SetLink to keep the various sectors in sync. Thanks again.
Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Re: Switch/Case Block

Post by Bob Evans »

I added a 3D Floor and somehow it worked right the first time although I am not sure exactly why. The 1st 2 are the floor and (4) other normal sectors while the 3rd is the 3D Sector. The tags for these sectors by chance were sequential meaning the 3RD Sector was the last tag number so I am assuming I just blundered on the right order. Is this correct otherwise I can't explain why it worked?
int floorheight;

script 11 (void)
{
if (floorheight == 1)
{
Floor_RaiseByValue (205, 3, 176);
Floor_RaiseByValue (205, 3, 176);
FloorAndCeiling_RaiseByValue (205, 3, 176);
tagwait(205);
floorheight=0;
terminate;
Delay(8);
}

if (floorheight == 0)
{
Floor_LowerByValue (205, 3, 176);
Floor_LowerByValue (205, 3, 176);
FloorAndCeiling_LowerByValue (205, 3,176);
tagwait(205);
floorheight=1;
terminate;
Delay(8);
}
User avatar
Gez
Developer
Developer
Posts: 1399
Joined: Mon Oct 22, 2007 16:47

Re: Switch/Case Block

Post by Gez »

Why do you have three different sector movement on the same sector(s)? Floor_Raise/LowerByValue is duplicated, and then followed by FloorAndCeiling_Raise/LowerByValue. Only keep one of those three lines in each block.

Also your code as you posted it is missing a closing curly brace, but I suppose it just wasn't selected with the rest when you copy/pasted it in your browser.

Finally, I don't see why a 3D floor would complicate matter in any way.
Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Re: Switch/Case Block

Post by Bob Evans »

Gez wrote:Why do you have three different sector movement on the same sector(s)? Floor_Raise/LowerByValue is duplicated, and then followed by FloorAndCeiling_Raise/LowerByValue. Only keep one of those three lines in each block.

Also your code as you posted it is missing a closing curly brace, but I suppose it just wasn't selected with the rest when you copy/pasted it in your browser.

Finally, I don't see why a 3D floor would complicate matter in any way.
I see your point about not needing both the 1st and 2nd lines as they are the same. The 3rd line, however, references the 3D Sector only.
My point in posting was to clarify how those 3 (now 2) lines perform the correct function to the right sector. It is determined from lowest tag number to highest tag number from the Link sector (not the link tag), correct?
I have only been scripting about 7 weeks part time so I may not understand everything yet.
I missed the closing brace when I copied. ACS would have complained otherwise. :)
User avatar
Gez
Developer
Developer
Posts: 1399
Joined: Mon Oct 22, 2007 16:47

Re: Switch/Case Block

Post by Gez »

It's the same sector tag you're using in all cases (205), and all of these effects affect all tagged sectors.
Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Re: Switch/Case Block

Post by Bob Evans »

Gez wrote:It's the same sector tag you're using in all cases (205), and all of these effects affect all tagged sectors.
It appears I am misinterpreting what is happening here. I commented out the 2nd and 3rd lines of the original 3 lines leaving just this:
Floor_RaiseByValue (205, 3, 176);
Everything works fine. As an experiment I tried just this line:
FloorAndCeiling_LowerByValue (205, 3,176);
and everything works the same so it doesn't matter which line I use it still works. This just points to the control sector (Sector_SetLink ) which contains the
the actual commands for the entire floor area including the 3D Sector? I am just trying to understand how this works. If all of the actions are performed on all the sectors then why doesn't the floor and ceiling rise and lower on all sectors?
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany

Re: Switch/Case Block

Post by Graf Zahl »

You'll have to post your map for someone to investigate. We are not clairvoyants.
Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Re: Switch/Case Block

Post by Bob Evans »

Graf Zahl wrote:You'll have to post your map for someone to investigate. We are not clairvoyants.
I never suggested anyone was clairvoyant. Are you referring to posting a screenshot of the map from GZDoom Builder?
Bob Evans
Posts: 14
Joined: Sun Dec 29, 2013 1:25

Re: Switch/Case Block

Post by Bob Evans »

Graf Zahl wrote:You'll have to post your map for someone to investigate. We are not clairvoyants.
Is this screenshot adequate?
You do not have the required permissions to view the files attached to this post.
Blue Shadow
Global Moderator
Global Moderator
Posts: 308
Joined: Sun Aug 29, 2010 6:09

Re: Switch/Case Block

Post by Blue Shadow »

Bob Evans wrote:
Graf Zahl wrote:You'll have to post your map for someone to investigate. We are not clairvoyants.
Is this screenshot adequate?
No, he meant to upload the map itself so it can be checked out.

Return to “GZDoom”