max and min values

Puuhaaja

Senior Member
Code:
irin [400,main], C.2, b0
if b0 = 18 then inc b5 
elseif b0 = 19 then dec b5
end if
I want that b5 will never grow bigger than 9 and smaller than 0

I tried different kind of
Code:
let b5 = max 9
codes but didn't get it workin
I'd like to use max/min commands because
Code:
if b5 = 10 then let b5 = 9
etc codes need much more space because there's so many places where I need that.

Greetings! Puuhaaja
 

Haku

Senior Member
Try this:
Code:
irin [400,main], C.2, b0
if b0 = 18 and b5 < 9 then inc b5 
elseif b0 = 19 and b5 > 0 then dec b5
end if
 

westaust55

Moderator
I'd like to use max/min commands
Using MIN and MAX commands saves a few (4) bytes:

Code:
irin [400,main], C.2, b0
if b0 = 18 then 
  b5 = b5 + 1 MAX 9 
elseif b0 = 19 then 
  b5 = b5 MIN 1 - 1
end if
Note that if you try b5 = b5 - 1 MIN 0 and b5 is already 0 then b5 = b5 - 1 ==> 255 so the MIN 0 will not create the 0 lower limit
 
Top