help with (if) statements

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
mikenet2007
Posts: 340
Joined: Wed Jan 24, 2007 8:54 pm

help with (if) statements

Post by mikenet2007 »

I need a combination of 3 switches to raise an elevator while each performs a function of its own.

all three switches raise support beams for the elevator near where each particular switch is located but its not until all three switches are presed that the elevator will function.

now because the switches are all on the elevator I don't want it set up to where one switch has to be pressed for another to function. I don't want any guess work for the player on this one so whatever button they happen to run to first should perform its function whether or not the other two have been pressed. It would only be the actual climbing of the elevator that would be dependent on all three switches having been pressed.

Problem is I have a low understanding of ACS (if) statements and variables and have always been best at design rather than programing although I do have many of the ACS basics understood.
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Post by Isle »

if you got it so you can only press each switch once you can just have a map var then add to it and then check it.
example:

Code: Select all

int sw = 0;

script 1 (void)//swtich script
{
    //beam stuff
    sw++;
    if(sw == 3)
    {
        //elevator stuff
    }
}
mikenet2007
Posts: 340
Joined: Wed Jan 24, 2007 8:54 pm

Post by mikenet2007 »

int sw = 0;

script 1 (void)//swtich script
{
//beam stuff
sw++;
if(sw == 3)
{
//elevator stuff
}


Yes each switch would be a one time hit, and there is no 4th switch as I forgot to mention. So in other words the third switch pressed lowers the last support beam, then raises the elevator.

Just to get your script understood I use it exactly as you have it but substitute //beam stuff, with the individual rise sectors for the support beams and //elevator stuff with the lines I have in ACS that operate my lift?
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Post by Isle »

yeah
mikenet2007
Posts: 340
Joined: Wed Jan 24, 2007 8:54 pm

Post by mikenet2007 »

Isle wrote:yeah


Ok its working but a problem I expected is occurring. Maybe you know what I'm doing wrong.

I need to individualize each button. This is how the script is set now......

script 1 (void)//swtich script
{
Floor_RaiseByValue (10,5,319);
Ceiling_LowerByValue (11,5,116);
Ceiling_LowerByValue (12,5,116);
sw++;
if(sw == 3)


{
Floor_LowerByValue (10,12,11610);
Ceiling_LowerByValue (10,12,11610);
FloorAndCeiling_RaiseByValue (1,4,3870);
FloorAndCeiling_LowerByValue (9,12,11610);
delay(100);
Thing_Spawn (1,T_ZOMBIE,0,0);
delay(100);
Thing_Spawn (2,T_ZOMBIE,0,0);
delay(100);
Thing_Spawn (1,T_ZOMBIE,0,0);
Thing_Spawn (2,T_ZOMBIE,0,0);
delay(100);
Thing_Spawn (1,T_ZOMBIE,0,0);
Thing_Spawn (2,T_ZOMBIE,0,0);
delay(100);
Thing_Spawn (1,T_IMP,0,0);
Thing_Spawn (2,T_IMP,0,0);
}
}
Each switch in the game is set up with H script execute (80)

however each switch performs all three actions....

Floor_RaiseByValue (10,5,319);
Ceiling_LowerByValue (11,5,116);
Ceiling_LowerByValue (12,5,116);

I need each switch to do one of these at a time before raising the lift, not all three each time the switch is hit.
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Post by Isle »

you could make the switches pass a varible to know what one was switched.
change the first part to

Code: Select all

script 1 (int tag)
{
  if(tag == 10)
    Floor_RaiseByValue (10,5,319); 
  else
    Ceiling_LowerByValue (tag,5,116);
  sw++;
//etc
then put the tag # thats suposed to move by the switch in the third arg of the line special.
mikenet2007
Posts: 340
Joined: Wed Jan 24, 2007 8:54 pm

Post by mikenet2007 »

Isle wrote:you could make the switches pass a varible to know what one was switched.
change the first part to

Code: Select all

script 1 (int tag)
{
  if(tag == 10)
    Floor_RaiseByValue (10,5,319); 
  else
    Ceiling_LowerByValue (tag,5,116);
  sw++;
//etc
then put the tag # thats suposed to move by the switch in the third arg of the line special.
I'm not sure what you mean, could you show me an example script? Maybe its my inexperience with scripts of this kind but I just don't get it.
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Post by Isle »

ok, the whole script would be

Code: Select all

script 1 (int tag) 
{ 
  if(tag == 10) 
    Floor_RaiseByValue (10,5,319); 
  else 
    Ceiling_LowerByValue (tag,5,116); 
  sw++;
  if(sw == 3) 
  { 
    Floor_LowerByValue (10,12,11610); 
    Ceiling_LowerByValue (10,12,11610); 
    FloorAndCeiling_RaiseByValue (1,4,3870); 
    FloorAndCeiling_LowerByValue (9,12,11610); 
    delay(100); 
    Thing_Spawn (1,T_ZOMBIE,0,0); 
    delay(100); 
    Thing_Spawn (2,T_ZOMBIE,0,0); 
    delay(100); 
    Thing_Spawn (1,T_ZOMBIE,0,0); 
    Thing_Spawn (2,T_ZOMBIE,0,0); 
    delay(100); 
    Thing_Spawn (1,T_ZOMBIE,0,0); 
    Thing_Spawn (2,T_ZOMBIE,0,0); 
    delay(100); 
    Thing_Spawn (1,T_IMP,0,0); 
    Thing_Spawn (2,T_IMP,0,0); 
  } 
} 
and for the switch line speclals (in the map, not the acs script) one needs to be:
ACS_EXECUTE(1, 0, 10, 0 ,0) for the floor tagged 10 one
ACS_EXECUTE(1, 0, 11, 0 ,0) for the celing tagged 11 one and
ACS_EXECUTE(1, 0, 12, 0 ,0) for the celing tagged 12 one
mikenet2007
Posts: 340
Joined: Wed Jan 24, 2007 8:54 pm

Post by mikenet2007 »

That works, I have some work to do with delays and height values but its doing what I want it to, I don't understand parts of the script, but as long as the basic functionality of the script does what its supposed to the rest I can work with.

Part of what I was confused about before was whether or not to set the arguments in ACS or in the editor, now I'm good, well I think unless the script has some unforeseen lasting effect on the sectors it moved that would prevent further changes in speed or height, I doubt it but I'll post back here if I have another problem.

Thanks
User avatar
Medricel
Posts: 1138
Joined: Sat Nov 20, 2004 9:47 am

Post by Medricel »

No, once the sectors stop moving, they are available to be moved again.
<randominfo>
Also, if you need an effect to occur when a moving floor stops, you can use TagWait(sectortag), which will wait until the sector with the specified tag stops moving before continuing, which could be handy for, say, timing an entrance door to open at the end of the elevator ride. </randominfo>
Locked

Return to “Editing (Archive)”