Primary parameters before 'bool'

Hey guys! So I did this codepad.org/87zCHfZx and it is giving an error totally out of my mind! Sorry if the code is really cluttered! My device has a character restriction of 4000 words. And I needed to compromise on code quality to squeeze that all in!
looks like you've been copying and pasting if(bool weapon==true) around :)

it should read if(weapon==true) and occurs in several places
Thanks mate! So you can use boolean values like normal integers? I mean dont have to stick 'int' after declaring once? Ill try your suggestion at once :D
So you can use boolean values like normal integers?


Well, yes. That makes more sense than inventing an entirely different syntax for using each variable type, doesn't it?

You specify the type of a variable when declaring/defining it. You don't need to put the type before it every time you used it, regardless of whether it's an int, a float, a bool, or a user-defined type.
The construction if (weapon==true) is unnecessarily verbose.
It amounts to evaluating the expression (weapon==true) and then testing the result to see whether it is true or false. With boolean types it is sufficient to put simply if (weapon).
@Chervil
Optimising compilers rule :)

I too use bools lin the way you describe, but i also think its important for learners to understand whats happening, optimising their source code isn't always a good thing and can lead to confusion.

@TheLoneWolf
Try renaming your bool variables to read like a statement that is either true or false.
eg; if (playerHasAWeapon) or while (gameInProgress) or if (playerIsOver21 && playerHasLivesLeft)
it will make your code read easier.
I will absolutely do that when on pc!
@Jaybob66 I've no wish to enter a debate here. I will only say that my aim was not to do the job of an optimising compiler. That is a misunderstanding. However I'd like to bow out gracefully here, please accept my apologies for doing so. Thanks everyone.
The construction if (weapon==true) is unnecessarily verbose.
And dangerous: What's the difference here

1) if (weapon==true)

2) if (weapon=true)

?
So
 
if (weapon)

is TRUE then what is FALSE?
Is
 
if (!weapon)

FALSE or I must simply write
 
if (weapon == false)

?
Either will work, but (!weapon) is more concise.
So will
1
2
3
4
5
6
7
bool x;

if (something == something && x)

//Will it work same as

if (something == something && x == true)

and will
1
2
3
4
5
6
7
bool x;

if (something == something && !x)

//Will this work the same as

if (something == something && x == false)

?
Topic archived. No new replies allowed.