Two switches and integer confusion

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Two switches and integer confusion

Post by Nirvana »

Ok, here is what I want to happen in my script:

I have two switches, you need the blue key for one and the red key for the other.
Essentially it is a button sequence ( nearly exactly the same as the one in the Zdoom community map) the only difference is that when you push one switch without the other, it still does something.
So basically you have to push both switches to complete the sequence, but pressing one will complete half the sequence.
But also, if you don't have the blue key and push the blue switch you will need to get a message....

I am terrible with integers in scripting, I just can't seem to get a good grasp of how to use them and the Wiki is fairly useless here...

I have worked on this for hours with pretty poor results, I appreciate that this is simply for a lot of people but I can't wrap my head around it :|

Any help would be GREATLY appreciated!

Thanks in advance..
User avatar
XutaWoo
Posts: 4005
Joined: Sat Dec 30, 2006 4:25 pm
Location: beautiful hills of those who are friends
Contact:

Re: Two switches and integer confusion

Post by XutaWoo »

[wiki]ACS_LockedExecute[/wiki]

Code: Select all

#include "zcommon.acs"

int sequence;
int button1press;
int button2press;

script 45 (void)
{
  if button1press == 1
    terminate;
  button1press = 1;
  sequence++;
  if (sequence == 2)
    (put stuff here)
}

script 46 (void)
{
  if button2press == 1
    terminate;
  button2press = 1;
  sequence++;
  if (sequence == 2)
    (put stuff here)
}
Knowing me, there's a less complicated method and some of the actual code isn't correct, but meh.
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: Two switches and integer confusion

Post by Nirvana »

You couldn't possibly explain that code could you? I kind of like to know what I'm putting in my scripts, for future reference and what not...
User avatar
XutaWoo
Posts: 4005
Joined: Sat Dec 30, 2006 4:25 pm
Location: beautiful hills of those who are friends
Contact:

Re: Two switches and integer confusion

Post by XutaWoo »

Code: Select all

script 45 (void)
{
  if button1press == 1 //this checks if we've pressed this button before
    terminate; //if so, stop the script
  button1press = 1; //elsewise, make it so that we can't press it again...
  sequence++;  //add 1 to sequence
  if (sequence == 2) //then check if sequence equals 2, if so do stuff
    (put stuff here)
}
It's similar for 46, except it uses a different check.
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: Two switches and integer confusion

Post by Nirvana »

I am actually going to get a knife and stab ACS in the face.

I really don't get this stuff, all I want is two switches that when pushed, perform their action, two actions are needed to complete the sequence, if you have pushed one switch it tells you 'one more switch to go', when the sequence is complete you get a message and if you don't have the keys for the switches it tells you, you need them.

I cannot wrap my head around these goddamn integers and there is no information on them whatsoever on the goddamn wiki, or anywhere else for that matter. ARRRGGH.

Thanks for your help man, but I'm apparently [censored word] because I still don't fully understand your script and can't get it to work the way I need it to :x :x :x
User avatar
XutaWoo
Posts: 4005
Joined: Sat Dec 30, 2006 4:25 pm
Location: beautiful hills of those who are friends
Contact:

Re: Two switches and integer confusion

Post by XutaWoo »

How old are you?

Intergers = Variables = SEVENTH GRADE AT THE MOST.

:?
User avatar
Lord_Z
Posts: 189
Joined: Sun Jun 15, 2008 2:11 pm
Location: Temporal Singularity

Re: Two switches and integer confusion

Post by Lord_Z »

Adding on to what XutaWoo said...

Code: Select all

//put these at the top of your code.
sequence = 0;
button1press = 0;
button2press = 0;

Code: Select all

script 45 (void)
{
  if button1press == 1    //this checks if we've pressed this button before
    terminate;                //if so, stop the script

  button1press = 1;        //if we have not pressed it before, make it so that we can't press it again 
                           //(next time the button is pressed, the first 'if' statement will be activated thus 
                           //stopping the script in its tracks)

  sequence++;               //add 1 to sequence (in this case sequence has been declared as being 0)

  if (sequence == 1)       //then check if sequence equals 1, if so do this stuff
      Print(s:"One more to go.");

  if (sequence == 2)       //then check if sequence equals 2, if so do this stuff
  {
     Print(s:"Sequence Completed!");
    //put more actions here, for instance 'Door_Open(tag, speed)'
  }
}

Code: Select all

script 46 (void)
{
  if button2press == 1    //this checks if we've pressed this button before
    terminate;                //if so, stop the script

  button2press = 1;        //if we have not, make it so that we can't press it again 
                           //(next time the button is pressed, the first 'if' statement will be activated thus 
                           //stopping the script in its tracks)

  sequence++;               //add 1 to sequence

  if (sequence == 1)       //then check if sequence equals 1, if so do this stuff
      Print(s:"One more to go.");

  if (sequence == 2)       //then check if sequence equals 2, if so do this stuff
  {
     Print(s:"Sequence Completed!");
     //put more actions here, for instance 'Door_Open(tag, speed)'
  }
}
Make one of the switches activate script 45 and the other switch activate script 46. Take the time to read this and once you have finished reading it, read it again. It should be very easy to understand.
User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: Two switches and integer confusion

Post by HotWax »

XutaWoo wrote:How old are you?

Intergers = Variables = SEVENTH GRADE AT THE MOST.

:?
... Um... No.

An "interger"(sic) is a natural number or a negative version of the same, or stated another way, a number with no fractional part.

A variable is a symbol that stands in for any number and has a value that may vary, or in programming terms is a symbolic name associated with a given value which may vary.

In programming, an int is a type of variable that can hold integer values between a given range, but that is probably not something you'd learn about in your 7th grade math class.
User avatar
Sonnyboy
Posts: 1156
Joined: Sun May 03, 2009 5:40 pm
Location: A pinch here, a dab there
Contact:

Re: Two switches and integer confusion

Post by Sonnyboy »

How about this? No integers, no checking, simple.

Lets say you have a square room with 2 switches coming up from the floor, and a small steplike thing to the lefthand side.

The tag of the steplike is 1.
The linetag of the red switch is 2.
The linetag of the blue switch is 3.

First, you give your blue key a special of 80, ACS Execute. The script it executes will be 1. Then, for the script the key will execute, type this--

Code: Select all

script 1 (void)
{
setlinespecial (3, 80, 2, 0, 0, 0, 0);
}
That way, the blue switch will execute the second script, now that you have the blue key. For these purposes, we'll just raise the steplike 6 X 8. You can do the same with a red key, only the linespecial it will setspecial will be 2. And that switch will simply raise the step another 6 X 8 units.
Here would be the hypothetical script--

Code: Select all


#include "zcommon.acs"

script 1 (void)
{
setlinespecial (3, 80, 2, 0, 0, 0, 0);
}
script 2 (void)
{
floor_raisebyvaluetimes8 (1, 20, 5);
}
script 3 (void)
{
setlinespecial (2, 80, 2, 0, 0, 0, 0);
}
I'll upload the wad if you don't understand it, but trust me, it works.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Two switches and integer confusion

Post by randi »

Sonnyboy wrote:setlinespecial (3, 80, 2, 0, 0, 0, 0);
You can use special names as parameters, so you can (and should) use the more readable form:

Code: Select all

setlinespecial(3, ACS_Execute, 2); 
User avatar
Nirvana
Posts: 156
Joined: Thu May 01, 2008 8:15 am

Re: Two switches and integer confusion

Post by Nirvana »

XutaWoo wrote:How old are you?

Intergers = Variables = SEVENTH GRADE AT THE MOST.

:?
I understand what an integer is, just not the implementation of them into the script that I am using. This may all seem trivial if you have done it before but it all looks a bit confusing when you are trying to take chunks from bits of other scripts and then work out the rest for yourself.

@Lord_Z
Got Xuta's code to work with this explanation, but I had to edit it because having (sequence=0) in the codes made it reset to that each time, so I didn't need it. Thanks for your help, pretty darn greatful :D

@Sonnyboy
I'll keep this in mind for future buttonometry, thanky.
User avatar
XutaWoo
Posts: 4005
Joined: Sat Dec 30, 2006 4:25 pm
Location: beautiful hills of those who are friends
Contact:

Re: Two switches and integer confusion

Post by XutaWoo »

Sonnyboy's requires the buttons be one after the other, though, else the players get confused.
Locked

Return to “Editing (Archive)”