if Val <0 then val =0 (val reaches 0) returns incorrect answer
I am run into a problem with this
Say i am decrementing a value that when it reaches zero I want it to remain zero
value=value-1
if value <=0 then Value = 0
what I get is
value = -1
returns
value= 15
if i try the min command I get the same result
also if i switch from declaring the variable from nib to byte the returned value will be 255 instead which is the largest value it will hold in both cases. what am i doing wrong as this isnt making sense to me any help will be appreciated.
Say i am decrementing a value that when it reaches zero I want it to remain zero
value=value-1
if value <=0 then Value = 0
what I get is
value = -1
returns
value= 15
if i try the min command I get the same result
also if i switch from declaring the variable from nib to byte the returned value will be 255 instead which is the largest value it will hold in both cases. what am i doing wrong as this isnt making sense to me any help will be appreciated.
Comments
IF·value > 0 THEN·value =·value - 1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
His value was < 0 or -1· or more precisely $F ( he did not state· value dismesion)
Someting to do with internal value being 16 bits or better yet signed integer ?
I just tryed this
VS VAR Bit
· VS = 0
··· DEBUG ? VS··············· prints VS = 0
··· DEBUG ? ~VS············· prints ~VS = 65535
··· DEBUG BIN1 ? ~VS······ prints ~VS = 1
··· DEBUG BIN16 ? ~VS···· prints ~VS = 1111111111111111
··· IF ~VS = 1 THEN
····· DEBUG "Debug ~VS = 0· " , ? VS skips debug· -· this should work!!!
··· ENDIF
··· IF ~VS = $FFFF THEN
····· DEBUG "Debug ~VS = $FFFF ", ? VS· prints ~VS = 0
··· ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Are you saying·that I cannot use ~ (complement) and then compare??
I do not have·to do it that way, but like to know the answer.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering