Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    true/false=1/0 not explained

    Bug Reporting (FUZE 4 Nintendo Switch)
    3
    3
    180
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pico8-jihem
      pico8-jihem F last edited by

      Documentation clarification: Using Controls', it's explained that controls(0).a returns true or false. In fact, the function returns 0 or 1 (if you print the value). At this step, we haven't explained that 0 is false and 1 is true. I may be wrong on this but I haven't found an explanation earlier.

      1 Reply Last reply Reply Quote 2
      • turtleStew
        turtleStew last edited by

        that's true (hehehe) in most languages. In some, I think C too, a boolean type takes a whole byte of memory so all the bits are dedicated to it. If a boolean is true, then all bits are high, the opposite is true if it's false. Using an integer value to represent this also works; just make it 0 or >0. However, signed integers can also be used to return negative values which are less than zero. This is often used to tell if an error occurred. But why use boolean types anyways? I think the best reasons to do so involve making the code somewhat more readable when there's no need for error handling

        ITzTravelInTime 1 Reply Last reply Reply Quote 1
        • ITzTravelInTime
          ITzTravelInTime F @turtleStew last edited by

          @turtleStew said in true/false=1/0 not explained:

          that's true (hehehe) in most languages. In some, I think C too, a boolean type takes a whole byte of memory so all the bits are dedicated to it. If a boolean is true, then all bits are high, the opposite is true if it's false. Using an integer value to represent this also works; just make it 0 or >0. However, signed integers can also be used to return negative values which are less than zero. This is often used to tell if an error occurred. But why use boolean types anyways? I think the best reasons to do so involve making the code somewhat more readable when there's no need for error handling

          that's how it works in c, flase is only produced by 0, all the other values are considered true, even with signed values, but some other languages implements boolean types using enumarative types or custom classes, that's to give more restrictive and specifiec usages to boolean types, or just to optimize the compilers for the usage of those values

          1 Reply Last reply Reply Quote 1
          • First post
            Last post