Generic Programming Question

This is a question that has always been on my mind when programming, not just in Gamesalad, either. What is truly the point of a Boolean variable? Yes, it gives a true or false value, but they're just 2 values. Any other number variable can store 2 variables, more than that. We could have an integer variable store 2 values of 1 and 0 (it could be any two numbers, you could have 19239 and 293 if you wanted, makes no difference) or with a string value (text on gamesalad), you could have two different words be two different values. What's the point of a boolean variable when any other variable could store even more values than it?

Having trouble with your game? Sounds like a personal problem.

Best Answers

  • gyroscopegyroscope I am here.Posts: 6,598
    edited August 2013 Accepted Answer

    Hi @ADSentertainment

    Good question; the answers as the other guys said – and to add:

    Booleans, being on or off, can also be considered in a "programming thought" way as yes or no... (or left or right, up or down, filled up or not.... millions of other things the boolean "switch" can be used for/considered as, in anyone's individual rules, whatever it's purpose is to register only one state as opposed to another).

    So it's a matter of efficiency, for certain (as said by QS & @ShinehouseGames), an attribute fine-tuned for its purpose, you could say.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • TheGabfatherTheGabfather Posts: 633
    Accepted Answer
    Getting deeper into it, Booleans should fit in a single bit, whereas an Integer/Number requires several bytes at times. This isn't ideal in my opinion though as using a single bit can get messy, hence they sometimes store it (a Boolean) within a byte by left-padding it with 0s. Although I am not sure how LUA does it.

    In any piece of software I have ever designed, I always made it a point to use Boolean whenever applicable for the simple reason that as stated it can only accept 2 values and the moment you feed it a value it does not recognise it should throw you an exception. This is easier to track compared to tracing an Integer or Number variable that is fed bad values.

Answers

  • quantumsheepquantumsheep Member Posts: 8,188
    edited August 2013
    I think it's a matter of efficiency.

    Think about it. A boolean can be very small, as it only has two possible values - on and off.

    An integer could have an infinite amount of whole values.

    I could just be talking rubbish of course, and it may make no difference!

    QS =D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • ShineHouseGamesShineHouseGames Member, PRO Posts: 100
    I'd like to think booleans are more clean and efficient. Though its effects on performance are probably negligible..
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Booleans are the original and most routine computer variable. There are only two possible states in computer circuits on or off. Everything else is a representing of a series of on off conditions called an algorithm. Take a moment and study binary math to understand how systems work under the hood.
  • ADSentertainmentADSentertainment Member Posts: 397
    edited August 2013
    Booleans are the original and most routine computer variable. There are only two possible states in computer circuits on or off. Everything else is a representing of a series of on off conditions called an algorithm. Take a moment and study binary math to understand how systems work under the hood.
    I know what binary is, if you're implying that I don't.

    Having trouble with your game? Sounds like a personal problem.

  • ADSentertainmentADSentertainment Member Posts: 397
    Getting deeper into it, Booleans should fit in a single bit, whereas an Integer/Number requires several bytes at times. This isn't ideal in my opinion though as using a single bit can get messy, hence they sometimes store it (a Boolean) within a byte by left-padding it with 0s. Although I am not sure how LUA does it.

    In any piece of software I have ever designed, I always made it a point to use Boolean whenever applicable for the simple reason that as stated it can only accept 2 values and the moment you feed it a value it does not recognise it should throw you an exception. This is easier to track compared to tracing an Integer or Number variable that is fed bad values.
    So are you saying that a boolean variable takes up less space than an integer variable? Since it only stores 2 values instead of...however many values that an integer variable can hold in Gamesalad?

    Having trouble with your game? Sounds like a personal problem.

  • TheGabfatherTheGabfather Member Posts: 633
    edited August 2013
    @ADSentertainment Ultimately it depends on the programming language/compiler you are using. I'm pretty sure Java as well as C++ will not store any Boolean value within a single bit in memory. In C, they actually use 1 byte (8 bits) to store a Boolean value since you shouldn't be allowed to store anything within less than a byte (this is probably the same with the aforementioned languages as well).

    I think an Integer/Number will automatically take 8 bytes from memory.

    ..but, concerning the limitations of what you can and cannot do (as of yet) with Gamesalad, I wouldn't worry about this if I were you. Just concentrate on choosing Boolean and Integer based on design (if you will) for your code. If something is designed to hold only two values, go with Bool. Otherwise, go with Integer.
Sign In or Register to comment.