how can i check if 2 triggers are pressed at the same time?
Moderator: Core Staff
how can i check if 2 triggers are pressed at the same time?
does anyone know?
Re: how can i check if 2 triggers are pressed at the same ti
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--;
    }
}
Â
-
- 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
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:
Change:
Code: Select all
if(level.trigsPressed >= 2 && i == 1)
{
/* both triggers are pressed at the same time, do your stuff. */
}
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
Re: how can i check if 2 triggers are pressed at the same ti
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
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.Drofder2004 wrote:anything inside the "if" statement will run twice when both buttons are pressed.
But it obviously needs testing. I still may be wrong.
Re: how can i check if 2 triggers are pressed at the same ti
i dont get why you have "trigger"+i
-
- 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
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.pcbouncer wrote:i dont get why you have "trigger"+i
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.
[...]
#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.
Who is online
Users browsing this forum: No registered users and 32 guests