Changing variable value depending on which trigger triggered last

I have two questions.

Question 1:
Suppose i have a set of triggers and a variable that latches on to a certain value depending on which trigger was triggered last. How do i do this?

SynthDef(\test, {
	var trig1, trig2, trig3, trig4;
	var mutableVar = 0;
	
	trig1 = Trig.ar(crossBeginCond & chanCond1, 0.01);
	trig2 = Trig.ar(crossBeginCond & chanCond2, 0.01);
	trig3 = Trig.ar(curHeadCond & chanCond1, 0.01);
	trig4 = Trig.ar(curHeadCond & chanCond2, 0.01);
        
        //some pseudo code
        if lasttrig == trig1
             mutableVar = 0
        else if lasttrig == trig2
             mutableVar = 1
        etc.
})

I feel like theres a simple solution to this. But i cant find it without making a mess.
I’d like to do this without the SendTrig, OSCFunc, synth.set way. So id like to keep this all inside the synth.

That brings me to question 2:
If i kept everything inside one synth instead of communication between client and server through osc messages and send trigs, would the timing improvement be significant?

There are two problems here. One is “latches on to,” which is solved by, well… Latch.

The catch here is that you want to latch when any of the four triggers fires. This is the logical-or operator. For signals, use ||.

Latch.ar(something, trig1 || trig2 || trig3 || trig4);

“Something” is the other problem.

Can you guarantee that only one trigger will fire at one time? If yes, then you could multiply:

(((trig1 > 0) * trig1value) + (((trig2 > 0) * trig2value) + etc...

Or

(([trig1, trig2, trig3, trig4] > 0) * [trig1value, trig2value, trig3value, trig4value]).sum

If triggers could possibly collide, then it gets trickier.

hjh