- Code: Select all
if(hp<0)hp=0;
Can be replaced with
- Code: Select all
hp=max(hp,0);
...
And
- Code: Select all
if(hp>maxhp)hp=maxhp;
Can be replaced with
- Code: Select all
hp=min(hp,maxhp);
...
But
How to replace both of them with no IFs?
if(hp<0)hp=0;
hp=max(hp,0);
if(hp>maxhp)hp=maxhp;
hp=min(hp,maxhp);
Bee-Ant wrote:How to replace both of them with no IFs?
hp=max(0, min(hp, maxhp));
int numControl(int none, int now, int most)
{
return max(none, min(now, most);
}
hp = numControl(0, hp, maxhp);
int hpControl(int hpNOW, int hpMAX)
{
return max(0, min(hpNOW, hpMAX) ;
}
hp = hpControl(hp, maxhp);
hp = min(((maxhp+hp) % maxhp), 0);
if(!strcmp(name,"bee-ant"))
switch(name){
case 'bee-ant': break;}
Bee-Ant wrote:Okay...
Could I replace IF for strcmp with switch-case?
- Code: Select all
if(!strcmp(name,"bee-ant"))
// in global code
enum namelist { beeant=0, dst=1, fuzzy=2, makslane=3, pyro=4, billgates = 5 };
// you dont need the =number. It can be used to give different values. you dont
// have to go 0,1,2,3,4,5.... you can skip number or repeat them 1,1,5,6,8,90,90,90
switch(intname) {
case beeant : break; }
// more global code
char names[] = {'beeant', 'dst', 'fuzzy', 'makslane', 'pyro', 'billgates'};
strcpy(name, names[intname]);
result = (hp > 45);
int isMore(int one, int two)
{
return( one > two);
}
int isLess(int one, int two)
{
return (one < two);
}
int isEqual(int one, int two)
{
return (one == two);
}
transp=max(status,1)-status;
Users browsing this forum: No registered users and 1 guest