Switch/Case Block
Moderator: Graf Zahl
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Switch/Case Block
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.
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.
-
- Developer
- Posts: 1399
- Joined: Mon Oct 22, 2007 16:47
Re: Switch/Case Block
[wiki]GetSectorFloorZ[/wiki]
-
- Developer
- Posts: 4751
- Joined: Tue Aug 30, 2005 23:19
- Location: Scotland
Re: Switch/Case Block
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:
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.
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;
}
}
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Re: Switch/Case Block
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.
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.
-
- Developer
- Posts: 4751
- Joined: Tue Aug 30, 2005 23:19
- Location: Scotland
Re: Switch/Case Block
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.
Presumably you could combine what I suggested with GetSectorFloorZ and use the GetSectorFloorZ value instead of the variable if you wanted.
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Re: Switch/Case Block
I added the DELAY as a safety. Went overboard again and added 4 sectors on the floor and everything works. Thank you.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.

Ended up changing things a bit. Added Sector_SetLink to keep the various sectors in sync. Thanks again.
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Re: Switch/Case Block
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);
}
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);
}
-
- Developer
- Posts: 1399
- Joined: Mon Oct 22, 2007 16:47
Re: Switch/Case Block
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.
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.
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Re: Switch/Case Block
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.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.
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.

-
- Developer
- Posts: 1399
- Joined: Mon Oct 22, 2007 16:47
Re: Switch/Case Block
It's the same sector tag you're using in all cases (205), and all of these effects affect all tagged sectors.
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Re: Switch/Case Block
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:Gez wrote:It's the same sector tag you're using in all cases (205), and all of these effects affect all tagged sectors.
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?
-
- GZDoom Developer
- Posts: 7148
- Joined: Wed Jul 20, 2005 9:48
- Location: Germany
Re: Switch/Case Block
You'll have to post your map for someone to investigate. We are not clairvoyants.
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Re: Switch/Case Block
I never suggested anyone was clairvoyant. Are you referring to posting a screenshot of the map from GZDoom Builder?Graf Zahl wrote:You'll have to post your map for someone to investigate. We are not clairvoyants.
-
- Posts: 14
- Joined: Sun Dec 29, 2013 1:25
Re: Switch/Case Block
Is this screenshot adequate?Graf Zahl wrote:You'll have to post your map for someone to investigate. We are not clairvoyants.
You do not have the required permissions to view the files attached to this post.
-
- Global Moderator
- Posts: 308
- Joined: Sun Aug 29, 2010 6:09
Re: Switch/Case Block
No, he meant to upload the map itself so it can be checked out.Bob Evans wrote:Is this screenshot adequate?Graf Zahl wrote:You'll have to post your map for someone to investigate. We are not clairvoyants.