Sign in to follow this  
Followers 0
biglam106

question about boolean and integer

3 posts in this topic

hi every body ! i have a problem i don't understand this code ( demos files " bakery" ) if FlourTank < 100 && !MoveMan then MoveMan = 1 endif if MoveMan then if MoveMan < 5 then MoveMan = MoveMan + 1 else MoveMan = 1 FlourTank = FlourTank + 10 endif my question is : 1. MoveMan = integer ( 1 to 10 ) and ( ! = not ) therefore the code "!MoveMan" = what's this ? 2.this code follow : if FlourTank < 100 && !MoveMan then MoveMan = 1 value = what's this ( boolean or integer ) 3 this code follow : if TankOpen && FlourTank then MillerOpen = FALSE if Miller < 100 then FlourTank = FlourTank - 5 Miller = Miller + 5 else TankOpen = FALSE endif else TankOpen = FALSE endif - tankopen = boolean - flourtank = integer => why to use " TankOpen && FlourTank " therefore what is new value of the expression ? please help me ! thank for reading looking forward answering Edited by biglam106

Share this post


Link to post
Share on other sites
Hi Biglam, I think I can see your confusion - all about mixing boolean expressions with integer operands. Hopefully I can help it make sense Firstly "!MoveMan" is just a shorter way of saying "!MoveMan == TRUE" or rather "MoveMan != FALSE". Now recognise that Boolean "FALSE" is always value 0, and Boolean "TRUE" is anything that is not 0 (although traditionally TRUE is 1, or -1, or 0xFFFF). So in psuedo code this line means "If the flour tank is not full, and the Man is not moving then start moving the Man" Actually there's the same issue later with the line "IF MoveMan THEN..." which is again shorthand for "IF MoveMan == TRUE THEN..." or rather "IF MoveMan != FALSE THEN...". Basically meaning "if the man is moving then..." So any integer can be used as a boolean expression (or with Boolean operators) where zero value means FALSE, or any other value evaluates to TRUE. (Why didn't I just say that! ) The same for "TankOpen && FlourTank" which again really means "TankOpen && (FlourTank != 0)" i.e. "if the valve is open, and there is flour in the tank..." Even more confused or does that sort it? Regards, Bertie Edited by Berti Baker

Share this post


Link to post
Share on other sites
Good response there Berti... and yes you are absolutely correct...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0