Clarifications about condition and logic : "If not" with the use of "or" and "and"

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:

Clarifications about condition and logic : "If not" with the use of "or" and "and"

#1 Post by sculpteur »

I have a little question about this line of code I have just written :

Code: Select all

menu:
        "Look around" if not obj_ducktape in inventory1.items or obj_ducktape in inventory2.items:
            jump my_label
The goal of this condition is to be sure the player don't have the item.
So I check the item IS NOT in inventory 1.
And I also check the item IS NOT in inventory 2.

But I am not sure about the second part of the line.
"If not obj_ducktape in inventory1.items" mean "obj_ducktape in inventory1.items == False"
but is it working for the secondary assertion ?
I want to be sure this line is the same thing than :
obj_ducktape in inventory1.items == False and obj_ducktape in inventory2.items == False

Could you give me you opinion on this please ?
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
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: Clarifications about condition and logic : "If not" with the use of "or" and "and"

#2 Post by Remix »

If inventory1.items is a list (and inventory2.items) you could:

"Look around" if not obj_ducktape in inventory1.items + inventory2.items:

Alternatively, use AND and explicitly define each condition:

"Look around" if not obj_ducktape in inventory1.items and not obj_ducktape in inventory2.items:
or
"Look around" if all( [ not obj_ducktape in inventory1.items, not obj_ducktape in inventory2.items ] ):
Frameworks & Scriptlets:

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Clarifications about condition and logic : "If not" with the use of "or" and "and"

#3 Post by Ocelot »

Your condition is parsed as

Code: Select all

(not (obj_ducktape in inventory1.items)) or (obj_ducktape in inventory2.items)
in has highest priority, followed by not and ending with or. You can follow Remix suggestion, or use not in operator + and:

Code: Select all

obj_ducktape not in inventory1.items and obj_ducktape not in inventory2.items
< < insert Rick Cook quote here > >

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: Clarifications about condition and logic : "If not" with the use of "or" and "and"

#4 Post by sculpteur »

I am not one hundred percent sure it's a list.
I have define it like this :

Code: Select all

python:
      inventory1 = Inventory1()
      inventory2 = Inventory2()
And after I use it like this :

Code: Select all

init -1 python:
    import renpy.store as store
    import renpy.exports as renpy # Needed so Ren'Py properly handles rollback with classes
    from operator import attrgetter # Needed this for sorting items

    item = None
    class Item(store.object):
        def __init__(self, name, image=""):
            self.name = name
            self.image=image # image file to use for this item
        def use(self):
            
            #USE ITEM which is in the INVENTORY
            if self.name == "Tools" and obj_tool_is_dropable and obj_tool in inventory1.items:
                inventory2.add(self)
                inventory1.drop(self)
or like this :

Code: Select all

        $ inventory1.add(obj_teddybear)
But anyway, thank a lot because I am almost sure that the line you give me will work.
My favorite is this one :

Code: Select all

"Look around" if not obj_ducktape in inventory1.items and not obj_ducktape in inventory2.items:
So thank you really much
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: No registered users