Combining fluid.ampslice~ / fluid.ampgate~

In my second (of likely more than a few of) reasking the same or similar questions about pd implementations, is it possible to do this kind of per-sample logic/debouncing in pd without gen~?

History state(0); 
History debounce(0); 
History prevValue(0); 

Param onthreshold(10); 
Param offthreshold(5); 
Param minslicelength(4410); 

if(state == 0 && in > onthreshold && prevValue < onthreshold && debounce == 0) 
{
  out1 = 1;   
  debounce = int(minslicelength); 	
  state = 1; 
} 
else 
{
	if(debounce > 0) debounce = debounce - 1; 
}
if(state == 1 && in1 < offthreshold) 
{
	state = 0; 
}
prevValue = in1; 
out2 = state; 

I can make sense of doing some of this logic with vanilla objects but setting/incrementing conditional counters is not something I’ve done with msp~-esque objects.