Measuring time passed between button press?

Musaic

L1: Registered
Dec 12, 2014
11
0
Hey guys I can't seem to figure out a good way to measure the seconds between a button pressed once then pressed again. Failing that, using a seperate start and stop button.

I wish to output the value to another entity. Any help would be appreciated!

Thanks
 

Da Spud Lord

Occasionally I make maps
aa
Mar 23, 2017
1,339
994
If you're okay with rounding down to the nearest second, you can try using a logic_timer with a length of 1 second that starts when the button is pressed, and when the logic_timer fires, it increments a math_counter by 1. You can possibly use the Toggle output on the logic_timer to start and stop it from the same button, or if that doesn't work, use two overlapping buttons that each disable themselves and enable the other when pressed, to give the illusion of a single button.
 

Musaic

L1: Registered
Dec 12, 2014
11
0
Hmm, I was hoping to be able to measure the time in milliseconds. I should have clarified. Thanks for the idea though.
 
Last edited:

Izotope

Sourcerer
aa
May 13, 2013
698
764
You should be able to set the logic_timer to 0.01
 

Izotope

Sourcerer
aa
May 13, 2013
698
764
math_counters don't accept float values though correct?
No idea, probably not. Though it doesn't hurt to try.
Even if it doesn't, you could still just add 1 with every millisecond, then OutValue that to a logic_case or multiple since they only have 16 cases each, and have each value represent a millisecond that triggers whatever event you want.
 

Musaic

L1: Registered
Dec 12, 2014
11
0
No idea, probably not. Though it doesn't hurt to try.
Even if it doesn't, you could still just add 1 with every millisecond, then OutValue that to a logic_case or multiple since they only have 16 cases each, and have each value represent a millisecond that triggers whatever event you want.

Awesome, I'll give it a shot when I get home.
 

Musaic

L1: Registered
Dec 12, 2014
11
0
Working!
I didn't need any logic cases either as unexpectedly the math_counter seems to accept float values. Thanks for the help!

I'm going to attempt to upload a test map if anyone else has issues getting it to work. The map uses the captured time to adjust the time between toggling the light in the center of the map on or off.
 

Attachments

  • tempo_test.vmf
    20.6 KB · Views: 250

henke37

aa
Sep 23, 2011
2,075
515
Careful about high frequency I/O, the system has safeguards against doing it on accident. For good reason.
 

Musaic

L1: Registered
Dec 12, 2014
11
0
Careful about high frequency I/O, the system has safeguards against doing it on accident. For good reason.

I figured as much, I'll only be implementing one in the map I'm making. I'll reduce the accuracy if I run into issues.