Page 1 of 1

(Solved) Question about Boolean Variables

Posted: Thu Oct 12, 2023 1:21 pm
by Two Dollars
New to ren'py. This functionality figures prominently in my game, so want to make sure I am doing it right. Here is my code:

Code: Select all

init:
    ## All variables are in a seperate varables.rpy file.

    $ crawlacrossfield = False
    $ walkacrossfield = False
    $ runacrossfield = False


label edgeofthefield:

    scene scene2image1
    pvts "This looks dangerous. What should we do?"

    scene scene2image2
        menu:
            "We should low crawl across.":
                $ crawlacrossfield = True
                jump crawlacrossfield
            "We should walk aross.":
                $ walkacrossfield = True
                jump walkacrossfield
            "We should run across.":
                $ runacrossfield
                jump runacrossfield

return


label crawlacrossfield:

    scene scene2aimage1
    mc "We're gonna low crawl. The tall grass will hide us from snipers."
    jump afteractionreview1


return


label walkacrossfield:

    scene scene2bimage1
    mc "We're gonna move carefully across. Watch your sectors of responsibilty."
    jump afteractionreview1

return


label runacrossfield:

    scene2cimage1
    mc "We're gonna run like Hell. We'll be across before they can react."
    jump afteractionreview1


return


label afteractionreview1:

    scene scene3image1

        co "Great job out there Sergeant."

    scene scene3image2

        mc: "Thank you, Sir."

        if crawlacrossfield == True:
            co "It was smart crawling to avoid snipers."

        elif walkacrossfield == True:
            co "I might not have moved that slow across a danger area."

        elif runacrossfield == True:
            co "It was smart to move quickly across the danger area."

    scene scene3image3

        co "Move your squad out, Sergeant."

return

Re: Question about Boolean Variables

Posted: Thu Oct 12, 2023 3:34 pm
by Alex
Two Dollars wrote: Thu Oct 12, 2023 1:21 pm ...
Change this

Code: Select all

init:
    ## All variables are in a seperate varables.rpy file.

    $ crawlacrossfield = False
    $ walkacrossfield = False
    $ runacrossfield = False
to

Code: Select all

## All variables are in a seperate varables.rpy file.

default crawlacrossfield = False
default walkacrossfield = False
default runacrossfield = False
https://www.renpy.org/doc/html/python.h ... -statement

Re: Question about Boolean Variables

Posted: Thu Oct 12, 2023 3:46 pm
by Two Dollars
Thank you, Alex.

Re: (Solved) Question about Boolean Variables

Posted: Thu Oct 12, 2023 4:24 pm
by Imperf3kt
Another tip is whenever you have something like

Code: Select all

if variable == True:
you've actually written

Code: Select all

if True == True
You can actually simplify that to

Code: Select all

if variable:

Re: (Solved) Question about Boolean Variables

Posted: Thu Oct 12, 2023 4:50 pm
by Two Dollars
Imperf3kt wrote: Thu Oct 12, 2023 4:24 pm Another tip is whenever you have something like

Code: Select all

if variable == True:
you've actually written

Code: Select all

if True == True
You can actually simplify that to

Code: Select all

if variable:
Would that look like...

if crawlacrossthefield:

Re: (Solved) Question about Boolean Variables

Posted: Fri Oct 13, 2023 5:10 am
by Imperf3kt
Two Dollars wrote: Thu Oct 12, 2023 4:50 pm
Would that look like...

if crawlacrossthefield:
Yes

Re: (Solved) Question about Boolean Variables

Posted: Fri Oct 13, 2023 9:53 pm
by Two Dollars
Thank you, Imperf.