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

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

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

Post by pcbouncer » May 29th, 2013, 11:35 pm

does anyone know?

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

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

Post by megazor » May 30th, 2013, 12:50 pm

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--;
        }
}
 

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

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

Post by Drofder2004 » May 30th, 2013, 7:47 pm

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. */
}
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

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

Post by pcbouncer » May 30th, 2013, 8:48 pm

thanks a lot!, i need to get used to understanding more complicated cod4 scripts, thanks again

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

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

Post by megazor » May 30th, 2013, 11:25 pm

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.

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

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

Post by pcbouncer » June 1st, 2013, 12:33 am

i dont get why you have "trigger"+i

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

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

Post by Rezil » June 1st, 2013, 1:16 am

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.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests