Minimum 0, maximum 1

Non-platform specific questions.

Minimum 0, maximum 1

Postby Hblade » Fri Jan 27, 2012 8:39 pm

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)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Minimum 0, maximum 1

Postby Game A Gogo » Sat Jan 28, 2012 12:49 am

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Minimum 0, maximum 1

Postby Hblade » Sat Jan 28, 2012 2:44 am

Ahh, thank you very much
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest