How boolean works

0 favourites
  • i want to know that how actually boolean works

    .

    suppose i have two sprites Sets (6 Red, 6 Black) in the middle of the layout i.e one over second sprite

    and layout have two buttons

    Red button and Black button

    .

    Now i want if i click Red button then black sprites should go out of layout

    and if i click black button then black sprite should came in and red's should go out

    .

    so here how i can use boolean

    .

    pls suggest

  • Boolean is not an action so it can't actually "work", it's a type of variable. There are various types of variables (of data types) where the most common are - let's say - string, integer and boolean. Let me explain you all of them, that should make you understang boolean better.

    String is a text type variable so you can store some text f.ex:

    • "Elvis is the only one real super hyper mega king of whole music history!" - this is some long text
    • "a" - this is a single character, but still a string, still a text
    • "1" - this is still a text, you see a digit but within the quotes it is treated as a string/text
    • "" - this is an empty string, like a text without a text but still engine treats it like a text if this is a string variable

    Integers are simply a digits like 0,1,2,3,4...

    Now as you can see strings and integers can have many different values. Boolean is a type of variable which can have only two different values: true or false. It is not a text "true" or "false", true or false it's just a logic assumption for the condition result. You can also think of it like the boolean may have only a value of 1 or 0. Switch is on or off.

    Now you probably wondering: "Why do we need a boolean if we can use Integer and just set it to 1 or 0, or even empty or not empty string?". Well that is a good question, and yes you can do it with integers and strings as well, but here are the reasons why you should use boolean if possible:

    Reason 1. To save some memory and what goes after increase performance. Depends on the programming languages, booleans may be a really tiny variables, but in other langs they are treated exactly the same like integers but just "wrapped" with the boolean functionality (something like "enum" in SQL).

    Reason 2. Safety. If you have a variable which should always be a digit, then you use integer, if a text then string if it's a switch/flag then boolean. If you use the proper variable type then you protect yourself from unwanted code results (calculation etc.).

    Reason 3. Because semantic code is the good code. This means that every functionality you build should be built using tools/elements which are dedicated for the particular functionality.

    If you are not an experienced develper then I understan those informations might be confusing or even sensless. Well but doing so is simply a good practice so I encourage you to stick to those rules, you will understand all the good things it brings once you'll get more and more andvanced developer. Especially once you start working in a team.

    I hope you get the meaning of boolean now, and as you see it doesn't "work", boolean is simply a flag which can hold one o two possible values officially accepted as true or false.

    If you write a game where you can turn on or off the lamp in the dark room, then you can use boolean to remember lamp's current state - isTheLampOn (true or false) etc.

    It is also worth to mention that if you think of it more closely then boolean is usually the answer for some question (is the lamp on? yes/no). Therefore a good practice is also naming boolean variables starting with "is", so the variable name itself tells you what question it's value answers to... like: isTheLampOn, isOnAir, isShooting, isMoving, isVisible etc.

    ALRIGHT! I was just about to write a short explanation and here's the "short" one haha.... but that is beautiful in development that even such a small thing as boolean is worth a discussion cause of its usability! .

  • Boolean is true and false and they are like integers. For example true represent 1 and false represent 0. Anyway , we use booleans to check states

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • boolean logic also allows thing like

    x=x+(x<10)

    so the (x<10) is either true (1) or false(0) so if x is less than 10 then add 1 to x, if x 10 or above then we add 0 to x ...

    so this could be used for a counter up to 10

    https://goo.gl/ypSYSo

  • thanks friend

    .

    its a long explanation

    .

    i read all the matter

    .

    Now i understand what is Boolean

    .

    .

    now question is how to use it

    So, Does my example belongs to Boolean

    .

    and what method will be for doing that

    Boolean is not an action so it can't actually "work", it's a type of variable. There are various types of variables (of data types) where the most common are - let's say - string, integer and boolean. Let me explain you all of them, that should make you understang boolean better.

    String is a text type variable so you can store some text f.ex:

    - "Elvis is the only one real super hyper mega king of whole music history!" - this is some long text

    - "a" - this is a single character, but still a string, still a text

    - "1" - this is still a text, you see a digit but within the quotes it is treated as a string/text

    - "" - this is an empty string, like a text without a text but still engine treats it like a text if this is a string variable

    Integers are simply a digits like 0,1,2,3,4...

    Now as you can see strings and integers can have many different values. Boolean is a type of variable which can have only two different values: true or false. It is not a text "true" or "false", true or false it's just a logic assumption for the condition result. You can also think of it like the boolean may have only a value of 1 or 0. Switch is on or off.

    Now you probably wondering: "Why do we need a boolean if we can use Integer and just set it to 1 or 0, or even empty or not empty string?". Well that is a good question, and yes you can do it with integers and strings as well, but here are the reasons why you should use boolean if possible:

    Reason 1. To save some memory and what goes after increase performance. Depends on the programming languages, booleans may be a really tiny variables, but in other langs they are treated exactly the same like integers but just "wrapped" with the boolean functionality (something like "enum" in SQL).

    Reason 2. Safety. If you have a variable which should always be a digit, then you use integer, if a text then string if it's a switch/flag then boolean. If you use the proper variable type then you protect yourself from unwanted code results (calculation etc.).

    Reason 3. Because semantic code is the good code. This means that every functionality you build should be built using tools/elements which are dedicated for the particular functionality.

    If you are not an experienced develper then I understan those informations might be confusing or even sensless. Well but doing so is simply a good practice so I encourage you to stick to those rules, you will understand all the good things it brings once you'll get more and more andvanced developer. Especially once you start working in a team.

    I hope you get the meaning of boolean now, and as you see it doesn't "work", boolean is simply a flag which can hold one o two possible values officially accepted as true or false.

    If you write a game where you can turn on or off the lamp in the dark room, then you can use boolean to remember lamp's current state - isTheLampOn (true or false) etc.

    It is also worth to mention that if you think of it more closely then boolean is usually the answer for some question (is the lamp on? yes/no). Therefore a good practice is also naming boolean variables starting with "is", so the variable name itself tells you what question it's value answers to... like: isTheLampOn, isOnAir, isShooting, isMoving, isVisible etc.

    ALRIGHT! I was just about to write a short explanation and here's the "short" one haha.... but that is beautiful in development that even such a small thing as boolean is worth a discussion cause of its usability! .

  • I'm programmer, I used construct for quick prototyping and decided to continue to work with c2 because the performance is not as bad I think. I have no idea about your structure but assuming if there are 4 types of object, redButton, RedSprite and blackButton and blackSprite then do something like

    event (on object clicked blackButton)

    for each object red

    set position to somewhere outside layout

    //and do the same for red one

    event (on object clicked redButton)

    for each object black

    set position to somewhere outside layout

    you might want to use boolean here (but I prefer number) if you only have one kind of object let's say a ColoredSprite and coloured button, they have both red and black animation, add an object isRed which is a boolean

    event (on object clicked coloredButton)

    for each coloredSprite

    if (coloreButton.isRed != coloredSprite.isRed)

    set position to somewhere outside layout

  • m not getting point correctly

    .

    i have done according to you

    it going outside screen

    but how to get them back .

    .

    .

    ex:

    click Red button > black sprite go out and red sprite came in

    click Black button ? red sprite go out and black sprite came in

    .

    how could i get this result

    I'm programmer, I used construct for quick prototyping and decided to continue to work with c2 because the performance is not as bad I think. I have no idea about your structure but assuming if there are 4 types of object, redButton, RedSprite and blackButton and blackSprite then do something like

    event (on object clicked blackButton)

    for each object red

    set position to somewhere outside layout

    //and do the same for red one

    event (on object clicked redButton)

    for each object black

    set position to somewhere outside layout

    you might want to use boolean here (but I prefer number) if you only have one kind of object let's say a ColoredSprite and coloured button, they have both red and black animation, add an object isRed which is a boolean

    event (on object clicked coloredButton)

    for each coloredSprite

    if (coloreButton.isRed != coloredSprite.isRed)

    set position to somewhere outside layout

  • here is my OTT boolean example (I will not be entering it into any good programming techniques competitions)

    https://goo.gl/OzoG3U

  • this file not opening

    saying : it is in 213 or newer version i have 212.2

    here is my OTT boolean example (I will not be entering it into any good programming techniques competitions)

    https://goo.gl/OzoG3U

  • How to open newer versions of capx files

    unzip the capx and edit the caproj file in a text editor

    find where is says (for example)

    <saved-with-version>21100</saved-with-version>

    and replace with an older number eg

    <saved-with-version>17000</saved-with-version>

    save and try

    Search the forum for more information about opening newer versions in old versions.

  • how we can unzip capx file

    .

    or what software will do this

    How to open newer versions of capx files

    unzip the capx and edit the caproj file in a text editor

    find where is says (for example)

    <saved-with-version>21100</saved-with-version>

    and replace with an older number eg

    <saved-with-version>17000</saved-with-version>

    save and try

    Search the forum for more information about opening newer versions in old versions.

  • I personally use 7zip (http://www.7-zip.org/) but there are quite a few "zip" programs available...

  • Thanks brother ! its working

    actually i was never know that these files can be zipped

    thanks again for this knowledge

    I personally use 7zip (http://www.7-zip.org/) but there are quite a few "zip" programs available...

  • i look at this one

    but i found 1 issues may because i never explained it before

    .

    actually my motive was

    i have one BG selection sprites

    and second is player selection sprites

    BG has 6 colour in frames

    Player have 6 players in frames

    and i have buttons of BG & player

    click BG i want change come BG sprites

    and click Player i want come player sprites

    this is the actual i need

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)