(Solved) Question about Boolean Variables

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Two Dollars
Newbie
Posts: 24
Joined: Wed Oct 11, 2023 1:51 pm
Deviantart: SophomoricEnt
Contact:

(Solved) Question about Boolean Variables

#1 Post 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
Last edited by Two Dollars on Sun Oct 22, 2023 11:56 pm, edited 3 times in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Question about Boolean Variables

#2 Post 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

Two Dollars
Newbie
Posts: 24
Joined: Wed Oct 11, 2023 1:51 pm
Deviantart: SophomoricEnt
Contact:

Re: Question about Boolean Variables

#3 Post by Two Dollars »

Thank you, Alex.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: (Solved) Question about Boolean Variables

#4 Post 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:
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Two Dollars
Newbie
Posts: 24
Joined: Wed Oct 11, 2023 1:51 pm
Deviantart: SophomoricEnt
Contact:

Re: (Solved) Question about Boolean Variables

#5 Post 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:

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: (Solved) Question about Boolean Variables

#6 Post by Imperf3kt »

Two Dollars wrote: Thu Oct 12, 2023 4:50 pm
Would that look like...

if crawlacrossthefield:
Yes
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Two Dollars
Newbie
Posts: 24
Joined: Wed Oct 11, 2023 1:51 pm
Deviantart: SophomoricEnt
Contact:

Re: (Solved) Question about Boolean Variables

#7 Post by Two Dollars »

Thank you, Imperf.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]