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

Two switches required

Question

How do I make a door open only by activating two switches (at any time)?

NOTE: include "common.acs" NOT "zcommon.acs"

I tried this:

 

Int door=0;

 

Script [script number] (void)

{

Door++;

If(door==2){

Door_open([tag], [speed]);

}

}

 

But the "int door=0;" -part affected all other scripts.

Edited by Pelle1986

Share this post


Link to post

Recommended Posts

  • 0

@Pelle1986  It really would have helped if you'd told us you weren't using (G)ZDoom!  To be honest if you're planning on making an advanced map, you might want to look into using GZDoom instead.  Not only is there far more materials for it, but it's pretty much become the more used port these days.  

Share this post


Link to post
  • 6

Don't bother with scripting.

 

Put a voodoo doll on a conveyor belt, put two thin doors blocking its path, tag each door to one of the switches, and put a walkover linedef behind the doors.

Share this post


Link to post
  • 1
4 minutes ago, Empyre said:

Maybe the variable declaration (int switchpresses =0;) needs to be at the top, before any of the scripts. It's worth a try.

I'm sorry but that did't help :-( But thanks anyway!

Share this post


Link to post
  • 0

I think it could be because of the name you chose for your variable. There is likely something in the system that has the name door.

Or maybe it is because the door variable is a global variable for all scripts. If you are using that variable in more than one script, each door needs to have a different variable with a unique name.

Share this post


Link to post
  • 0
47 minutes ago, Pelle1986 said:

But the "int door=0;" -part affected all other scripts.

If you have multiple scripts that operate multiple doors, then you also need multiple map scope variables, one for each script. If you declare them outside the scripts, you need to give a different name to each variable. It's convenient to use the static keyword to declare the map scope variables within the scripts themselves, then each variable will be unique to its script even if their names were identical.

Share this post


Link to post
  • 0

In Tormentor's MAP01 of tnt3.wad is such a script for a sequence of two switches to be activated

 

Spoiler

y1Bo564.png

 

Edited by Kappes Buur : spoiler added

Share this post


Link to post
  • 0

When you say it "affected all other scripts", affected them how? 

 

The above posters are probably right though. Try changing the name of your Int to something like "UniqueDoorIntOfWonder" and it should work fine.

Share this post


Link to post
  • 0
9 hours ago, scifista42 said:

If you have multiple scripts that operate multiple doors, then you also need multiple map scope variables, one for each script. If you declare them outside the scripts, you need to give a different name to each variable. It's convenient to use the static keyword to declare the map scope variables within the scripts themselves, then each variable will be unique to its script even if their names were identical.

Thanks!

I forgot to mention that I am very novice when it comes to scripting. I would be thankful if you could give me an example. Show me how it could looj like, please. Thanks again!

/ Per 

Share this post


Link to post
  • 0
6 hours ago, Bauul said:

When you say it "affected all other scripts", affected them how? 

 

The above posters are probably right though. Try changing the name of your Int to something like "UniqueDoorIntOfWonder" and it should work fine.

Hi!

It affected them in way that made all other scripts "canceled". It seems they didn't work.

I need an example how to write this script. Thanks alot!

Share this post


Link to post
  • 0
11 hours ago, Empyre said:

I think it could be because of the name you chose for your variable. There is likely something in the system that has the name door.

Or maybe it is because the door variable is a global variable for all scripts. If you are using that variable in more than one script, each door needs to have a different variable with a unique name.

Thanks!

Can you please give an example how that may look? Can I name it whatever I like? "Door001" for example??

/Per 

Share this post


Link to post
  • 0

This should work fine, put the same exact script on both switches.

int switchPresses = 0;
script [script number] (void)
{
	switchPresses = switchPresses + 1;
	Delay(1);
	if(switchPresses == 2) Door_Open([tag], [speed]);
}

 

Share this post


Link to post
  • 0
7 hours ago, Nevander said:

This should work fine, put the same exact script on both switches.


int switchPresses = 0;
script [script number] (void)
{
	switchPresses = switchPresses + 1;
	Delay(1);
	if(switchPresses == 2) Door_Open([tag], [speed]);
}

 

Hi!

No, that won't make it because the line "int switchpresses = 0;" will cancel all other scripts i made. There must be another way. Thanks anyway.

/Per

Share this post


Link to post
  • 0

I don't understand... that is just the variable and it has map scope. Running the script once will set it to 1, running again sets it to 2. I've done many scripts like this for my own maps and they all work just fine. That line is just the variable declaration and is not part of the script.

Share this post


Link to post
  • 0
14 minutes ago, Nevander said:
14 minutes ago, Nevander said:

 

Hi again!

I have a few scripts so I just copy all of them here. Take a look please:

 

#include "common.acs"

script 1 (void)
{
    Polyobj_RotateLeft (1,6,64);
    polyobj_RotateRight (2,6,64);
    ACS_Terminate (1, 0);
}

script 2 (void)
{
    delay(150);
    Thing_Deactivate(3);
    Light_Fade(1,20,12);
    Light_Fade(2,20,12);
    delay(50);
    Floor_LowerByValue(2,16,112);
}

int switchPresses = 0;

script 3 (void)
{
    switchPresses =
switchPresses + 1;
    Delay(1);
    if(switchPresses == 2) Door_Open(4,16);
    Door_Open(4,16);
}


Okey, that is all. I put both swiches to action 80 - script execute, script number= 3, map number= 0, script arg 1, 2 and 3 = 0.

Script 1 and 2 just work as soon as I erase the line "int switchpresses =0;"

I just don't understand what I am doing wrong.

/Per

 

Share this post


Link to post
  • 0
On 07/10/2017 at 9:51 PM, Pelle1986 said:

How do I make a door open only by activating two switches (at any time)?

 

Make said switches both crush a barrel in a void sector that will each kill a Commander Keen, 666-tag the door.

I know you're specifying ZDoom scripts here, but there's a vanilla-compatible fallback just in case.

 

EDIT
When I had suggested this, it was not known exactly what OP was going for; which turned out to be Doomsday/Hexen. I think. ;)

Edited by Jayextee

Share this post


Link to post
  • 0
2 minutes ago, Jayextee said:

 

Make said switches both crush a barrel in a void sector that will each kill a Commander Keen, 666-tag the door.

I know you're specifying ZDoom scripts here, but there's a vanilla-compatible fallback just in case.

Hi!

I am sorry, I don't know what you mean. Commander Keen? Vanilla-compatible??

/Per

Share this post


Link to post
  • 0

Maybe the variable declaration (int switchpresses =0;) needs to be at the top, before any of the scripts. It's worth a try.

Share this post


Link to post
  • 0

So is there any particular reason why nobody here is using the && operator for this? ._.

#include "zcommon.acs"

bool Switch1 = false;
bool Switch2 = false;

void checkdoors(){
  if (Switch1 && Switch2){ //If both Switch1 and Switch2 have both been set to True,
		Door_Open(1, 64); //Then open the door or do whatever.
  }
  //Optional Else clause to tell the player there is one more switch remaining
  else{
    print(s:"\c[Green]One more to go.");
  }
  	
}

script 1 (void){ //Execute this script once when player presses a switch
	Switch1 = true; //Set the first switch bool to true,
	checkdoors(); //Then execute the function which checks to see if both the bools have been set to open the door.
}

script 2 (void){ //Same as above.
	Switch2 = true;
	checkdoors();
}

This to me, looks way more efficient and easier to read and understand than this weird counter thing you guys are trying to do.

Share this post


Link to post
  • 0

I don't see why this would have anything to do with the variable declaration affecting the script, but why is ACS_Terminate there? You have it terminating the script it is in, but the script would terminate on its own without it. Removing that shouldn't fix the problem we are trying to fix, but stranger things have happened.

 

Also, instead of swtichPresses = switchPresses + 1; you could have simply used switchpresses++; which is not only less to type, but compiles to more efficient code. If ACS supports putting the ++ before a variable, you could go even further and have it all reduced to

if (++switchPresses == 2) Door_Open(4,16);

Putting the ++ before the variable adds one before checking the value, while putting the ++ after the variable checks the value before adding one.

 

Also, you have Door_Open(4,16); appearing for a second time after the if statement, which means that the door will always open no matter what.

 

EDIT: Ninja'd by a pretty elegant solution.

Share this post


Link to post
  • 0
7 minutes ago, Praetor said:

So is there any particular reason why nobody here is using the && operator for this? ._.


#include "zcommon.acs"

bool Switch1 = false;
bool Switch2 = false;

void checkdoors(){
  if (Switch1 && Switch2){ //If both Switch1 and Switch2 have both been set to True,
		Door_Open(1, 64); //Then open the door or do whatever.
  }
  //Optional Else clause to tell the player there is one more switch remaining
  else{
    print(s:"\c[Green]One more to go.");
  }
  	
}

script 1 (void){ //Execute this script once when player presses a switch
	Switch1 = true; //Set the first switch bool to true,
	checkdoors(); //Then execute the function which checks to see if both the bools have been set to open the door.
}

script 2 (void){ //Same as above.
	Switch2 = true;
	checkdoors();
}

This to me, looks way more efficient and easier to read and understand than this weird counter thing you guys are trying to do.

Hi!

Sorry, but that did not work either :-(

Namnlös2.png

Share this post


Link to post
  • 0

You are including "common.acs" when it should be "zcommon.acs" In Praetor's method it should be function void by the way, not just void. That's why you get that error.

 

 

26 minutes ago, Praetor said:

So is there any particular reason why nobody here is using the && operator for this? ._.

This to me, looks way more efficient and easier to read and understand than this weird counter thing you guys are trying to do.

Apples and oranges here. I prefer counters because I think in terms of two switches to use, use one that's 1 used, use both is 2. Compare against number of used switches with a counter. Both ways work the same, different approach.

 

 

24 minutes ago, Empyre said:

Also, instead of swtichPresses = switchPresses + 1; you could have simply used switchpresses++; which is not only less to type, but compiles to more efficient code. If ACS supports putting the ++ before a variable, you could go even further and have it all reduced to

if (++switchPresses == 2) Door_Open(4,16);

Putting the ++ before the variable adds one before checking the value, while putting the ++ after the variable checks the value before adding one.

Personally I've always preferred doing the long way. It helps me understand the code and makes it obvious for anyone reading it back. It's more logical and usually I don't like shorthand. In my mind I can see 0 = 0 + 1 is 1, then 1 + 1 = 2. Makes more sense to me that way. Once again same end result, different approach. Never had a problem doing it the long way. I don't really see how it would be more efficient, they both happen in the same tic anyway.

Share this post


Link to post
  • 0
Just now, Pelle1986 said:

#include "common.acs"

This is supposed to be "zcommon.acs".

But anyways, my bad, I appear to have mistyped the ACS.

 

function void checkdoors(void) { 
  if (Switch1 && Switch2){
    Door_Open(1, 64);
  }
}

 

That should do it.

Share this post


Link to post
  • 0
6 minutes ago, Nevander said:

 including "common.acs"

Yes, I include "common.acs" because I have tried "zcommon.acs" for so long time and it has never worked. I have tried to get help at this very forum and many have tried to help but nothing ever changed the fact that scripting doesn't work. The last answer I received was that it doesn't work on all computers and no one knows why. That is another story, however...

Are you saying that I can't make those switches by including "common.asc"?

Share this post


Link to post
  • 0
43 minutes ago, Praetor said:

This is supposed to be "zcommon.acs".

But anyways, my bad, I appear to have mistyped the ACS.

 


function void checkdoors(void) { 
  if (Switch1 && Switch2){
    Door_Open(1, 64);
  }
}

 

That should do it.

Thanks!

But i can't use "zcommon.acs". It just won't work. Many have tried to help me but failed. I've tried to reinstall doombuilder and stuff. Nothing helps. Then I tried "common.acs" and scripting all of a sudden worked :-)

Share this post


Link to post
  • 0

Wtf... that makes no sense because common.acs isn't even a thing AFAIK. I don't have that file, only zcommon.acs.

 

EDIT: Wait, there is a common.acs for compiling Hexen ACS scripts. I think you are using the wrong common file. The one you want is zcommon.acs but it should be used automatically if you are making a ZDoom map. Is your map pure Hexen format by chance? Because if so, you don't get full ACS support.

 

Ok try this really quick. Copy and paste this into a map SCRIPTS and try to compile, JUST this.

#include "zcommon.acs"

script 1 (void)
{
	Delay(1);
}

Does it work? If so then so should anything else provided you don't make syntax errors. If it didn't work, post the error. I'm thinking maybe your zcommon.acs is corrupted or missing or some other weird shenanigans.

Share this post


Link to post
  • 0
9 minutes ago, Nevander said:

Wtf... that makes no sense because common.acs isn't even a thing AFAIK. I don't have that file, only zcommon.acs.

 

Ok try this really quick. Copy and paste this into a map SCRIPTS and try to compile, JUST this.


#include "zcommon.acs"

script 1 (void)
{
	Delay(1);
}

Does it work? If so then so should anything else provided you don't make syntax errors. If it didn't work, post the error. I'm thinking maybe your zcommon.acs is corrupted or missing or some other weird shenanigans.

Okej, I got this error message:

"Couldn't find include file "zcommon.acs"

 

I looked for it and it is located at C:/Doom Buider 2/Configurations/Includes

Share this post


Link to post
  • 0

What format are you mapping in? Something tells me Hexen because if including common.acs works and zcommon.acs doesn't, it sounds like Hexen format (not ZDoom). In my Doom Builder 2 folder I have a Compilers folder, then a Hexen folder with common.acs and a ZDoom folder with zcommon.acs. Mapping in ZDoom is when you use zcommon.acs. There's really no reason to map in standard Hexen unless you plan to run it with the vanilla executable.

Share this post


Link to post
  • 0
6 minutes ago, Nevander said:

What format are you mapping in? Something tells me Hexen because if including common.acs works and zcommon.acs doesn't, it sounds like Hexen format (not ZDoom). In my Doom Builder 2 folder I have a Compilers folder, then a Hexen folder with common.acs and a ZDoom folder with zcommon.acs. Mapping in ZDoom is when you use zcommon.acs. There's really no reason to map in standard Hexen unless you plan to run it with the vanilla executable.

Yes, it is Hexen format. I have tried "ZDoom(Hexen)" and whether the "zcommon.acs" is found or not, scripting don't work. It is as if the game (which is run by DoomsDay (snowberry.exe)) can't read the scripts. For example: I make a switch which opens a door, by scripting. While in game and I press the switch, it lights up but nothing happends. And BELIVE me I have checked everything such as tag, ceiling hights etc.

Share this post


Link to post
  • 0

Oh, you're making a Hexen map for Doomsday! Doomsday has its own native formats for maps and scripts. They're doing great stuff, but it is all incompatible with everything else. I suggest using their manual and forums to help you learn how to take advantage of the Doomsday engine.

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
×