Python class and contition inside a Renpy Menu

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
sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Python class and contition inside a Renpy Menu

#1 Post by sculpteur »

Hi,

I would like to check a condition which come from a Python script in a Renpy Menu but I have no idea how.

First (optional question) :

Is this line of code :

Code: Select all

label 1:
    $ inventory.add(obj_teddybear)
Is the same thing than this one? :

Code: Select all

label 1:
     python:
          inventory.add(obj_tool)



Secondly, i have this renpy menu with condition :

Code: Select all

label 2:
    menu:
        "Go look for it":
            jump DarkBasment3_a
        "Go back":
            jump DarkBasment3_b
        "Go check the generator" if obj_teddybear is in inventory.items and progression_find_jess_dark == True :
            jump DarkBasment3_Generator
Its making an error (wrong sythax).

In my inventory screen I use this loop :

Code: Select all

    for item in inventory.items:
         blablabl
and its working, so my class and variables are ok.

Its just I have no Idea how to express a condition in Python INSIDE a renpy menu code.

If anyone know how to make this let me know plz.
Thanks.
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Python class and contition inside a Renpy Menu

#2 Post by xavimat »

1. Label names can't start with numbers.
2. The '$' symbol is used in Ren'Py language for one-line python commands. So, yes, these two are the same:

Code: Select all

$ inventory.add(an_obj)

python:
    inventory.add(an_obj)
3.Check your syntax:

Code: Select all

if an_obj in inventory.items
AND NOT: if an_obj IS in inventory.items
4. When checking boolean variables, these two are the same (and the second is preferred):

Code: Select all

if my_variable == True:
    # do something...
if my_variable:
    # do something...
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Python class and contition inside a Renpy Menu

#3 Post by Remix »

Ditto-ish reply...

First:
Yup, both are (pretty much) the same... just use the python: block for multi line python ... (pretty much = one adds tool, one adds teddy)

Second:
Lose the word is
"Go check the generator" if obj_teddybear in inventory.items and progression_find_jess_dark == True:
Frameworks & Scriptlets:

sculpteur
Veteran
Posts: 312
Joined: Fri Nov 17, 2017 6:40 pm
Completed: Apocalypse Lovers
Projects: Apocalypse Lovers
Organization: Awake_Production
Location: France
Discord: https://discord.gg/apocalypse-lovers
Contact:

Re: Python class and contition inside a Renpy Menu

#4 Post by sculpteur »

WoW NICE !
This langage is really intuitive.
When I wrote : "if an_obj is in inventory.items" I completly made it up lol. Just like if I was talking to the computer ^^

I was about to write it without the "IS" but I was thinking " no way its gonna work " ^^

Thanks you guys !
Image

“He asked me to calm down, close my eyes and be quiet. He explained to me that if I was afraid, the shadow that ran barefoot in the street would feel it. I got scared seeing Jumanji on TV, so let me tell you, we didn't stay hidden for long and had to start running again.”
Jessica's Diary.

Post Reply

Who is online

Users browsing this forum: Google [Bot]