Boolean VS Number Variable

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Is there any difference in performance if I use a number variable with value 0 and 1 versus a boolean? What are some advantages of using boolean instead of number variable? Thanks.

  • The boolean variable only needs to store one byte of information. So a boolean variable is slightly better for storage and performance. But only very, VERY slightly. So unless you have literally a million variables, it won't make a difference.

    I would recommend using a boolean variable, just because it lets you do things, like toggle the boolean. Which is surprisingly difficult to achieve with a number variable.

  • You can toggle a number variable which is either 0 or 1 using,

    abs(variable -1) or 1-variable

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • What are some advantages of using boolean instead of number variable?

    For better code readability and debugging. Doesn't affect machine execution if you are comparing it against 1 and 0. But :

    playerJumping == true [/code:1r2dvnv4]
    is more human readable than say :
    [code:1r2dvnv4] playerJumping == 1 [/code:1r2dvnv4]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)