Let me tell you about my favorite function that I wrote years ago: minus_one()
Here it is in all it's glory:
function minus_one(value) {
return max(value-1,0);
}
Yes, all it does is subtract 1 from a value without that value going below 0. Pretty simple, but I use it all the time. It's a real workhorse of my code. It's mainly used in timers, things that are reduced each frame and than do something when they hit 0.
What are some of your commonly used functions folks?