Python Vs Renpy Condition_Check

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 Vs Renpy Condition_Check

#1 Post by sculpteur »

Hellow,

I'am working on this portion of python code :

Code: Select all

        def use(self, item):
            if item.usable and item in self.items:
                self.items.remove(item)
                print("", "Item used!")
            else:
                print("", "Item can't be used!")
WHAT I'M TRING TO DO (SHORT VERSION) :
I just want to check a condition in this python code, BUT I don't want to do it inside this fonction and I don't know how to get out this fonction to call a label or an other fonction.



WHAT I'M TRING TO DO (LONG VERSION) :
I'am using different items and I want a different effect for each of them when they are used.
But I have a lot of items, so I don't want to incorporate the "what_item_is_used" inside this fonction.
I prefer to go back to renpy code because I'am more at my ease with it that I am with Python.

So it would be great if someone can show me how to go out this fonction and check which items in a renpy label.

Something like

Code: Select all

        def use(self, item):
            if item.usable and item in self.items:
                self.items.remove(item)
                jump label_what_item_is_used
                print("", "Item used!")
            else:
                print("", "Item can't be used!")

Code: Select all

label label_what_item_is_used:
            if self.items == apple:
                You eat an apple.
                Hunger - 15
            if self.items == water:
                You drink water.
                Thrist - 15
etc, etc ...




Just for let you know, this is the other part of the code relevant to this.

Code: Select all

    class Item(store.object):
        def __init__(self, name, image="", trashable=True, usable=True):
            self.name=name
            self.image=image
            self.trashable = trashable
            self.usable= usable

    class Inventory(store.object):
        def __init__(self, spaces = 4):
            self.items = []
            self.spaces = spaces

        def add(self, item):
            if self.has_space():
                self.items.append(item)
                return True
            else:
                return False

        def trash(self, item):
            if item.trashable and item in self.items:
                self.items.remove(item)
                print("", "Item is trashed!")
            else:
                print("", "Item can't be trashed!")

        def drop(self, item):
            if item in self.items:
                self.items.remove(item)
                print("", "Item dropped!")
            else:
                print("", "Item can't be dropped!")

        def use(self, item):
            if item.usable and item in self.items:
                self.items.remove(item)
                print("", "Item used!")
            else:
                print("", "Item can't be used!")

Code: Select all

    items = {
        "Null_Item": Item("Null_Item", image="gui/item_icon_tools.png"),
#   Quest_Item
        "Revolver": Item("Revolver", image="gui/item_icon_weapon_revolver.png", trashable=False, usable=False),
        "Tools": Item("Tools", image="gui/item_icon_tools.png", trashable=False, usable=False),
        "Ducktape": Item("Ducktape", image="gui/item_icon_ducktape.png", trashable=False, usable=False),
        "Sponge": Item("Sponge", image="gui/item_icon_sponge.png", trashable=True, usable=False),
#   Generic_Item
        "FoodFruit1": Item("FoodFruit1", image="gui/item_icon_foodfruit_1.png", trashable=True, usable=True),
        "WaterBottleEmpty": Item("WaterBottleEmpty", image="gui/item_icon_waterbottle_empty.png", trashable=True, usable=True),
        "Rice": Item("Rice", image="gui/item_icon_rice.png", trashable=True, usable=True),
        "Wood": Item("Wood", image="gui/item_icon_wood.png", trashable=True, usable=True),
        }
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.

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python Vs Renpy Condition_Check

#2 Post by philat »

Well, I wouldn't do it that way. But renpy.jump will let you jump anywhere. *shrug*

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 Vs Renpy Condition_Check

#3 Post by sculpteur »

Could you be more specific 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.

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python Vs Renpy Condition_Check

#4 Post by philat »

I'm not sure what there is to be more specific about. renpy.jump is the python equivalent of the jump statement. https://www.renpy.org/doc/html/statemen ... renpy.jump

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 Vs Renpy Condition_Check

#5 Post by sculpteur »

Of course. Of course but I was talking about this part sorry :
philat wrote: Tue Mar 26, 2019 5:12 am Well, I wouldn't do it that way.
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.

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 Vs Renpy Condition_Check

#6 Post by sculpteur »

In fact I have this action in my imagebutton :

Code: Select all

imagebutton:
            idle pic
            hover pic xpos x ypos y
            action blablabla
            alternate [Hide("gui_tooltip"), Play ("sound", "0 - sound_useitem.mp3"), Function(inventory.use, item)]
And I'am wondering where and how should I check the condition for my items type.
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.

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python Vs Renpy Condition_Check

#7 Post by philat »

Well, jumping to a separate label and going through an if/elif tree defeats a large part of the purpose of having items as objects anyway. So, I would try to figure out how to use items without doing that, but I don't know what kind of items you have or what kind of game you're designing, so it's hard to be more specific about that.

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 Vs Renpy Condition_Check

#8 Post by sculpteur »

philat wrote: Wed Mar 27, 2019 10:29 pm Well, jumping to a separate label and going through an if/elif tree defeats a large part of the purpose of having items as objects anyway. So, I would try to figure out how to use items without doing that, but I don't know what kind of items you have or what kind of game you're designing, so it's hard to be more specific about that.
You are really intersting me.
jumping to a separate label and going through an if/elif tree
What's wrong with this? If I don't get lost in my own code it's right, no ?

Code: Select all

the purpose of having items as objects 
Which it is ?

Code: Select all

the kind of items you have or what kind of game you're designing
I consider Item in my game like imagebutton i my game inventory.
You left-click them, you move them from one container to another.
You right-click them, you got an effect if the item is usable.
https://ibb.co/4FRnRmC
Some are consumable (they are destroyed on use, like food) some other are not.

Like you saw, the "use" fonction is fine. It removed consumable item after use. But I 'm looking for the best way and the best place to put the code for the item_check and for the item_effect.
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
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Python Vs Renpy Condition_Check

#9 Post by trooper6 »

You have text that is specific to each item. "You eat an apple" and you have actions that are specific to each item "thirst -15" -- since that stuff is specific to each item...I would include it in the definition of the items themselves...so then you don't need to jump to some label.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python Vs Renpy Condition_Check

#10 Post by philat »

I mean... I'm not going to go into a ton of detail because that's thinking work, but a large part of the point of classes is to let you put everything about the item IN the class and then be able to reference the class object rather than do it elsewhere. There's nothing wrong with doing it in a label with an if/elif tree as long as it works, but by the same token, you could also construct a screen with an if/elif tree instead of being able to do something like Function(inventory.use, item) but it would be a shit ton of typing. You've managed to abstract the .remove() method so that it's workable for all items -- depending on what your items are, it could be simple to abstract the .use() method as well (for instance, if the items are all consumables that buff or debuff stats, you could read the affected stat and the size of effect from the item and act on it in the use() method) -- or it may be more complicated. Again, I don't know what your game is, and I'm not particularly interested in working out the details (again, that is substantial thinking work), but if I were you, that is what I would be thinking about.

Post Reply

Who is online

Users browsing this forum: Vamp-sama