Page 1 of 1

how can i check if 2 triggers are pressed at the same time?

Posted: May 29th, 2013, 11:35 pm
by pcbouncer
does anyone know?

Re: how can i check if 2 triggers are pressed at the same ti

Posted: May 30th, 2013, 12:50 pm
by megazor
Not tested

Code: Select all

main()
{
        level.trigsPressed = 0;
        n = 2;
        for(i = 0; i < n; i++)
                getEnt("triggggger"+i, "targetname") thread trig(i);
}
 
trig(i)
{
        while(1)
        {
                self waittill("trigger");
                level.trigsPressed++;
                if(level.trigsPressed >= 2)
                {
                        //both triggers are pressed at the same time, do your stuff.
                }
                wait .05;       // optional?
                level.trigsPressed--;
        }
}
 

Re: how can i check if 2 triggers are pressed at the same ti

Posted: May 30th, 2013, 7:47 pm
by Drofder2004
The only problem with the code is that the function "trig()" is running twice. So anything inside the "if" statement will run twice when both buttons are pressed.

Change:

Code: Select all

if(level.trigsPressed >= 2 && i == 1)
{
   /* both triggers are pressed at the same time, do your stuff. */
}

Re: how can i check if 2 triggers are pressed at the same ti

Posted: May 30th, 2013, 8:48 pm
by pcbouncer
thanks a lot!, i need to get used to understanding more complicated cod4 scripts, thanks again

Re: how can i check if 2 triggers are pressed at the same ti

Posted: May 30th, 2013, 11:25 pm
by megazor
Drofder2004 wrote:anything inside the "if" statement will run twice when both buttons are pressed.
I doubt it. If two triggers are pressed at the same server frame, either function will be done first way. But not both two at the very same time. So, the first function to start will set level.trigsPressed to 1, then without any pauses it will do the if statement, leaving no chance for the second function to change it to 2. And then the second function will start - and the check will be successfull in that case.

But it obviously needs testing. I still may be wrong.

Re: how can i check if 2 triggers are pressed at the same ti

Posted: June 1st, 2013, 12:33 am
by pcbouncer
i dont get why you have "trigger"+i

Re: how can i check if 2 triggers are pressed at the same ti

Posted: June 1st, 2013, 1:16 am
by Rezil
pcbouncer wrote:i dont get why you have "trigger"+i
It's so you can index your triggers in Radiant (for example "trigger_0", "trigger_1", "trigger_2" and so on) and easily get each of them using a loop.