Generic Programming Question
ADSentertainment
Member Posts: 397
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
-
gyroscope I am here.Posts: 6,598
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
-
TheGabfather Posts: 633Getting 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
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
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Having trouble with your game? Sounds like a personal problem.
Having trouble with your game? Sounds like a personal problem.
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.