Page 1 of 1

Minimum 0, maximum 1

PostPosted: Fri Jan 27, 2012 8:39 pm
by Hblade
Hey guys. I'm kind of stuck here. I was trying to make a switch function very similar to RPG maker. I want to be able to have the minimum be a 0 and the max be a 1. I tried this:
Code: Select all
void ChangeSwitch(int AR, int VALUE) {
    SWITCH[AR]=min(VALUE, max(SWITCH[AR], 1));
                              }

Now how would I go about limiting it without using an if statement or too much code?

I also tried
Code: Select all
VALUE=min(0, max(VALUE, 1));

but that doesn't work either. (This code placed above switch[ar] code)

Re: Minimum 0, maximum 1

PostPosted: Sat Jan 28, 2012 12:49 am
by Game A Gogo
it's
Code: Select all
VALUE=max(0, min(VALUE, 1));


Think about it, max returns the maximum value. If VALUE is -1, it will return 0, and vice versa about min

Re: Minimum 0, maximum 1

PostPosted: Sat Jan 28, 2012 2:44 am
by Hblade
Ahh, thank you very much