Door with button


(jkfloris) #1

I try to make a door which fully opens when you press a button 3 times.
I use this script

door_1_TST

{
	spawn
	{
	wait 50
	accum 7 set 0
	}


	trigger activate

	{
		accum 7 trigger_if_equal 0 door_1 open1
		accum 7 trigger_if_equal 1 door_1 open2
		accum 7 trigger_if_equal 2 door_1 open3

	}

}



door_1

{

	trigger open1

	{

		faceangles 0 30 0 800 wait	
		wait 2500
		accum 7 set 1
		trigger door_1 dicht
	}

	trigger open2
	{
		faceangles 0 60 0 800 wait
		wait 2500
		accum 7 set 2
		trigger door_1 dicht

	}

	trigger open3
	{
		faceangles 0 90 0 800 wait
	}

	trigger dicht
	{
		faceangles 0 0 0 800 wait
	}

}

The door opens the first 30 degrees, but when I press the button again
the door doesn’t open 60 degrees, but still 30°

Is it possible this way, or do I have to make 3 buttons?


(kamikazee) #2

You just made a crucial mistake with your accums. Accums are only defined within the entity they are used in. On the other hand, globalaccums work for the whole script.

So in this case, accum 7 in door_1_TST always stays “0” while accum 7 in door_1 is changed.

Here is one way to make your script work, take a close look at my changes:

door_1_TST
{
   trigger activate
   {
      trigger door_1 open
   }
}



door_1

{
   spawn
   {
      wait 50
      accum 7 set 0
   }

   trigger open
   {
      accum 7 inc 1

      accum 7 trigger_if_equal 1 door_1 open1
      accum 7 trigger_if_equal 2 door_1 open2
      accum 7 trigger_if_equal 3 door_1 open3
   }


   trigger open1
   {
      faceangles 0 30 0 800 wait   
      wait 2500
      trigger door_1 close
   }

   trigger open2
   {
      faceangles 0 60 0 800 wait
      wait 2500
      trigger door_1 close
   }

   trigger open3
   {
      faceangles 0 90 0 800 wait
   }

   trigger close
   {
      // Button needs to be pushed 3 times again
      accum 7 set 0
      faceangles 0 0 0 800 wait
   }
}

(jkfloris) #3

thanks for explaining the difference.

Now I will be able to finish this part of the map.


(jkfloris) #4

unfortunately, there is an other problem:

every time I push the button the script “thinks” I pressed the button twice.
here is the output of /g_scriptdebug 1:


47300 : (door_1_TST) GScript event: trigger activate
47300 : (door_1_TST) GScript command: trigger door_1 open
47300 : (door_1) GScript event: trigger open
47300 : (door_1) GScript command: accum 0 inc 1
47300 : (door_1) GScript command: accum 0 trigger_if_equal 1 door_1 open1
47300 : (door_1) GScript event: trigger open1
47300 : (door_1) GScript command: faceangles 0 20 0 800 wait

there is no action!
and the script continues


47400 : (door_1_TST) GScript event: trigger activate
47400 : (door_1_TST) GScript command: trigger door_1 open
47400 : (door_1) GScript event: trigger open
47400 : (door_1) GScript command: accum 0 inc 1
47400 : (door_1) GScript command: accum 0 trigger_if_equal 1 door_1 open1
47400 : (door_1) GScript command: accum 0 trigger_if_equal 2 door_1 open2
47400 : (door_1) GScript event: trigger open2
47400 : (door_1) GScript command: faceangles 0 60 0 800 wait
48200 : (door_1) GScript command: wait 2500

the door opens

when I press the button again:


52700 : (door_1_TST) GScript event: trigger activate
52700 : (door_1_TST) GScript command: trigger door_1 open
52700 : (door_1) GScript event: trigger open
52700 : (door_1) GScript command: accum 0 inc 1
52700 : (door_1) GScript command: accum 0 trigger_if_equal 1 door_1 open1
52700 : (door_1) GScript command: accum 0 trigger_if_equal 2 door_1 open2
52700 : (door_1) GScript command: accum 0 trigger_if_equal 3 door_1 open_final
52700 : (door_1) GScript event: trigger open_final
52700 : (door_1) GScript command: faceangles 0 90 0 800 wait

same story: no action and the script continues


52800 : (door_1_TST) GScript event: trigger activate
52800 : (door_1_TST) GScript command: trigger door_1 open
52800 : (door_1) GScript event: trigger open
52800 : (door_1) GScript command: accum 0 inc 1
52800 : (door_1) GScript command: accum 0 trigger_if_equal 1 door_1 open1
52800 : (door_1) GScript command: accum 0 trigger_if_equal 2 door_1 open2
52800 : (door_1) GScript command: accum 0 trigger_if_equal 3 door_1 open_final
52800 : (door_1) GScript command: accum 0 trigger_if_equal 4 door_1 close
52800 : (door_1) GScript event: trigger close
52800 : (door_1) GScript command: faceangles 0 0 0 800 wait
53600 : (door_1) GScript command: accum 0 set 0

here is the script I use:


door_1_TST
{
   trigger activate
   {
      trigger door_1 open
   }
}



door_1
{
	spawn
	{
		accum 0 set 0
	}

	trigger open
	{
		accum 0 inc 1

		accum 0 trigger_if_equal 1  door_1 open1

		accum 0 trigger_if_equal 2 door_1 open2

		accum 0 trigger_if_equal 3 door_1 open_final

		accum 0 trigger_if_equal 4 door_1 close
   	}


	trigger open1
	{
		faceangles 0 20 0 800 wait   
		wait 2500
	}

	trigger open2
	{
		faceangles 0 60 0 800 wait
		wait 2500
	}

	trigger open_final
	{
		faceangles 0 90 0 800 wait
	}

	trigger close
	{
		faceangles 0 0 0 800 wait
		accum 0 set 0
	}
}

edit:
when I use


	trigger open
	{
		accum 0 inc 1

		accum 0 trigger_if_equal 2 door_1 open1

		accum 0 trigger_if_equal 4 door_1 open2

		accum 0 trigger_if_equal 6 door_1 open_final

		accum 0 trigger_if_equal 8 door_1 close
   	}

the door works as expected, so I will use this part in the script
The question still remains: why?


(kamikazee) #5

What do you mean with “there’s no action”? According to the debug info, all statements get executed like they should.


(jkfloris) #6

the door doesn`t move


(-SSF-Sage) #7

Why do you have to wait for 2,5 seconds there? I think that will cause you 2,5x2=5 seconds pause, if you press the button three times in row (which is very long time waiting for…I would have closed it as not working…). If you wanted that 2,5 stop, wouldn’t it be better to give it

setstate (targetname of the button or such) invisible
wait 2500
setstate (targetname) default

, or remove the wait 2500? I’m just guessing.

Edit hmm. It should move at the first press… i think. Well long day at work, no more thinking today…


(kamikazee) #8

Check that only one entity has a targetname “door_1” and only one “door_1_TST”.