Topic: BOOLEANS in Maratis (LUA)(Tutorial)

WHAT IS A BOOLEAN?

A boolean is an offspring of a guy named George Boole. So any child of George Boole is a boolean. hahaha.

NO REALLY! WHAT IS A BOOLEAN?

A boolean is a DATA TYPE (a type of data) that has only two possible values, TRUE and FALSE.

WHAT IS A DATA TYPE?

Well, text is a type of data. A number is a type of data. Data is considered the building blocks of information, and we store information in the form of text/words and numbers/integers.

SO WHAT IS A BOOLEAN AGAIN?

A boolean is data that can only be one of two values, TRUE and FALSE, which are represented by the numbers 1 and 0 (1 is true, 0 is false)

WHAT ARE BOOLEANS USED FOR?

Booleans are used to ACTIVATE and DEACTIVATE stuff. It actually goes back to how computers work. A computer is just a bunch of electrical components at the end of the day, which are either ON or OFF depending on the flow of current.

Imagine you had a computer screen that was set up like this:

xxxxxxxxx
xxxxxxxxx
xxxxxxxxx

The resolution of your computer screen would be 9 by 3 Xs.

Each x represents a light bulb, and at any given time, some lightbulbs will be on, and others will be off. In fact, if these lightbulbs flicker fast enough, your screen will look like one solid color.

Using some very complex circuitry tricks you can control the way the Xs flicker.

These ONs and OFFs or 1s and 0s can be manipulated to create things like DISPLAYING PIXELS on your computer.

That is what a boolean is used for.

Say we have a variable:

light =

If we want to make it a BOOLEAN, we can either give it the value TRUE or the value FALSE. By default a light is off so:

light = false

What does this mean in our program? Well, that light = false! Nothing more.

But we can use this light variable to control things. We can use it with a CONDITIONAL STATEMENT to control when things happen:

lightBulb = getObject("LightBulb")

if light==false then
    setObjectIntensity(lightBulb,0)
end

So, as long as light = false, then the intensity of the lighBulb object will be 0.
But, as soon as we change the light boolean variable to TRUE, then we can can change the intensity to full brightness.

lightBulb = getObject("LightBulb")

if light==false and isKeyPressed("L")then
    setLightIntensity(lightBulb,1)
    light = true


elseif light==true and isKeyPressed("L")then
    setLightIntensity(lightBulb,0)
    light = false
    
end

So, this says that if light=false and you press the "L" key, set the intensity of the lightbulb object to 100%. Also, set light to true (now light=true and not false)

On the other hand, if light=true (it's true now because we made it true by pressing "L") and you press the "L" key, then set the lighbtbulb's intenstity to 0. Also, set light equal to false (so that if we press "L" again it will work, because light has to be equal to false for it to work).

This is how we can use booleans to TOGGLE

I always like to put these types of things into a nice little function:

light_1 = getObject("Light1")
light_2 = getObject("Light2")

function ToggleLight(object)
    if light==false and isKeyPressed("L")then
        setLightIntensity(object,1)
        light = true


    elseif light==true and isKeyPressed("L")then
        setLightIntensity(object,0)
        light = false
    end
end

Notice how I used an ARGUMENT so that I can make whichever light I put into the parenthesis able to turn on and off. Used like this:

ToggleLight(light1)
ToggleLight(light2)

Etc.

OTHER POSSIBLE USES OF BOOLEANS:

We can use booleans to have things happen based on a character's current state/emotion

george = getObject("George")

happy=false
sad=false
normal=true

function BeEmotional()
    if normal==true then
        changeAnimation(george,0)
        sad=false
        happy=false
    elseif happy==true then
        changeAnimation(george,1)
        normal = false
        sad=false
    elseif sad== true then
        changeAnimation(george,2)
        happy=false
        normal=false
    end
end

If I were to use Object Oriented Programming and a few ARGMENTS I could make this a bit easier to use and re-use.

Last edited by Tutorial Doctor (2014-04-28 17:46:34)

Re: BOOLEANS in Maratis (LUA)(Tutorial)

You should put your tutorials in the wiki also, so they don't get lost. As a programmer you get an A+ in your explanation of a BOOLEAN. You even added a touch of humor. wink

Re: BOOLEANS in Maratis (LUA)(Tutorial)

I just sent an email to anael to see if it is possible. Thanks.
This has been a neat adventure, learning programming and game development. I don't know how much longer I will do it, but I have learned a lot, and it may come in handy. I like to post tutorials so that other's who might want to learn can have an easier time.

I am not savvy enough like you and com3d and 255 and anael though, haha. I was hoping I could potentially get a job in it, but it seems people are so much further ahead than I am that I would not even have a chance. haha.

Thanks Zester. smile

Re: BOOLEANS in Maratis (LUA)(Tutorial)

Tutorial Doctor wrote:

I just sent an email to anael to see if it is possible. Thanks.
This has been a neat adventure, learning programming and game development. I don't know how much longer I will do it, but I have learned a lot, and it may come in handy. I like to post tutorials so that other's who might want to learn can have an easier time.

I am not savvy enough like you and com3d and 255 and anael though, haha. I was hoping I could potentially get a job in it, but it seems people are so much further ahead than I am that I would not even have a chance. haha.

Thanks Zester. smile

In Indie Game Development, the people who spend the money are the ones who cant "Program" and or "Produce there own Assets" that's where the money is. Those who make the money are the ones who write the "Tutorials", "Short Scripts", "Produce Assets".

Doing these things is like being a doctor, we will always need doctors. And trust me it takes a special type to produce the pieces needed to make a game.

I have a friend who makes a living off of making "Icons" and "Themes" for Android Apps, that's all he does and he makes a good living. It's very rare to come across a "Programmer" that is also an "Artist".

As far as being savy, learning to "Program" doesn't take long learning to be a great "Programmer" takes years. In regards to Art I have only been doing the art side for 2 years and that's only because I had to learn everything by my self. I do this for no other reason than pure enjoyment its my me time.

I would stick to it unless it's not something you really wan't to do, you defiantly have talent.

Note: Re-targeting BVH animations to a rig is not an easy task. I have had only limited success in my attempts, as have most. And you can sell your Makehuman models with your custom textures.