Python code item and Load/Save bug

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 code item and Load/Save bug

#1 Post by sculpteur »

Hello everyone,

I have a problem which is really simple and I know from my memory of precedent asked questions that this kind of stuff is frequent with Renpy, but I can't figure it out, neither where I read that, nor how to fix it.

Let me explain,
I have an inventory system, ( you can see it in image here : https://i.imgur.com/Z4CbASa.png ) which is working.
But, when you get one item, save the game, then reload a previous save before you found it, this item is still in you inventory.
I have to idea how to begin to try solving that even if I read the tuto about what's is save and what's not saved by rendpy (https://www.renpy.org/doc/html/save_load_rollback.html).

I already tinker a workaroud for my item system to be compatible with the rollback system but I can't do it with SAVE/LOAD system.

So I will show you the way I define the inventory system in Python and the way I add an item in the inventory during a playthrouht and maybe one of the clever minds which hang up aroud here will be able to identify how I should solve this.

How I add an item during a playthrough

Code: Select all

$ inventory.add(items["Ducktape"])

My inventory system

Code: Select all

    class Player(renpy.store.object):
        def __init__(self, name, max_main_health=0, max_main_hunger=0, max_main_thirst=0, max_main_energy=0, max_main_sleep=0, max_main_moral=0, max_main_tension=0, element=None):
            self.name=name
            self.max_main_health=max_main_health
            self.main_health=max_main_health
            self.max_main_hunger=max_main_hunger
            self.main_hunger=max_main_hunger
            self.max_main_thirst=max_main_thirst
            self.main_thirst=max_main_thirst
            self.max_main_energy=max_main_energy
            self.main_energy=max_main_energy
            self.max_main_sleep=max_main_sleep
            self.main_sleep=max_main_sleep
            self.max_main_moral=max_main_moral
            self.main_moral=max_main_moral
            self.max_main_tension=max_main_tension
            self.main_tension=max_main_tension
            self.element=element
    player = Player("Derp", 100, 50)



    class Item(store.object):
        def __init__(self,
            name,
            player=None,
            cost=0,
            main_health=0,
            main_hunger=0,
            main_thirst=0,
            main_energy=0,
            main_sleep=0,
            main_moral=0,
            main_tension=0,
            element="",
            image="",
            trashable=True,
            usable=True):

            self.name=name
            self.player=player # which character can use this item?
            self.cost=cost # how much does it cost in shops?
            self.main_health = main_health # does this item modify health?
            self.main_hunger = main_hunger # does this item modify hunger?
            self.main_thirst = main_thirst # does this item modify thirst?
            self.main_energy = main_energy # does this item modify energy?
            self.main_sleep = main_sleep # does this item modify sleep?
            self.main_moral = main_moral # does this item modify moral?
            self.main_tension = main_tension # does this item modify tension?
            self.element=element # does this item change elemental damage?
            self.image=image
            self.trashable = trashable
            self.usable= usable

        def use(self): #here we define what should happen when we use the item
            if self.main_health>0: # healing item
                player.main_health = player.main_health+self.main_health
                if player.main_health > player.max_main_health: # can't heal beyond max HP
                    player.main_health = player.max_main_health
                inventory.drop(self) # consumable item - drop after use
            elif self.main_hunger>0: # hunger restore item
                player.main_hunger = player.main_hunger+self.main_hunger
                if player.main_hunger > player.max_main_hunger: # can't increase hunger beyond max
                    player.main_hunger = player.max_main_hunger
                inventory.drop(self) # consumable item - drop after use
            elif self.main_thirst>0: # thirst restore item
                player.main_thirst = player.main_thirst+self.main_thirst
                if player.main_thirst > player.max_main_thirst: # can't increase thirst beyond max
                    player.main_thirst = player.max_main_thirst
                inventory.drop(self) # consumable item - drop after use
            elif self.main_moral<0: # moral gain item
                player.main_moral = player.main_moral+self.main_moral
                if player.main_moral > player.max_main_moral: # can't increase moral beyond max
                    player.main_moral = player.max_main_moral
            elif self.main_moral<0: # moral down item
                player.main_moral = player.main_moral-self.main_moral
                if player.main_moral < 0: # can't decrease moral beyond zero
                    player.main_moral = 0
            else:
                player.element=self.element #item to change elemental damage; we don't drop it, since it's not a consumable item


    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:
                item.use()

        def has_space(self):
            return len(self.items) < self.spaces


    class Container(store.object):
        def __init__(self, allowed=[], allow_all=False, spaces = 4):
            self.items = []
            self.allowed = allowed
            self.allow_all = allow_all
            self.spaces = spaces

        def add(self, item):
            if self.allow_all or item in self.allowed:
                self.items.append(item)
                return True
            else:
                return False

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

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

        def clear_container_found(self, item):
            self.items.remove(item)

        def has_space(self):
            return len(self.items) < self.spaces



    def move_item(from_container, to_container, item):
        if to_container.add(item):
            if not from_container.drop(item):
                print("", "Failed to drop [item.name]!")
            else:
                print("", "Item moved")
        else:
            if to_container.has_space():
                print("", "Failed to add [item.name] for some reason.")
            else:
                print("", "Failed to add [item.name]: out of space!")

Code: Select all

init python:

    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),
        "Towel": Item("Towel", image="gui/item_icon_towel.png", trashable=True, usable=False),
        "Soap": Item("Soap", image="gui/item_icon_soap.png", trashable=True, usable=False),
balablab etc etc
and this

Code: Select all

    inventory = Inventory()
    container = Container()
    container_null = Container([items["Null_Item"]])
    inventory_big = Container("Container", allow_all=True)

    container1 = Container([items["Ducktape"], items["Tools"]])
    container2 = Container([items["Teddybear"]])
    container3 = Container([items["Towel"], items["Sponge"], items["Bassin"], items["Soap"]])
    container4 = Container([items["Manche"]])
    container5 = Container()

    container_gift_1 = Container([items["RedApple"]])

    container_food = Container([items["FoodRationSmall"], items["FoodRationBig"], items["FoodCan"], items["Rice"]])
    container_gaztank = Container([items["Butane"]])
    container_generator = Container([items["Gasoline"]])
    container_cloth = Container([items["Clothes"], items["SewingKit"], items["Fabric"]])
    container_toiletries = Container([items["Clothes"]])
    container_alcohol= Container([items["WineCalifornian"], items["WineItalian"], items["WineFrench"]])

    container_fillwater = Container([items["WaterBottleEmpty"]])

    container_found = Container("Container", allow_all=True)
    container_trash = Container("Container", allow_all=True)
# Container space
    inventory.spaces = 4
    inventory_big.spaces = 14
    container_found.spaces = 13
    container_food.spaces = 1
    container_trash.spaces = 1
My rollback workarout

And, if, just by curiosity, you are interested about my lame workaround to make it work with the rollback system in order to avoid item duplication, this is the code:

Code: Select all

    if not items["Ducktape"] in inventory.items and not items["Ducktape"] in inventory_big.items:
        $ inventory.add(items["Ducktape"])
Do not hesitate to comment this also if you want to tell me how dumb I am that's fine I already know it but at least this anti-rollback part is working lol
And it's still better than this : $ renpy.block_rollback() double lol
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
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Python code item and Load/Save bug

#2 Post by gas »

When you create objects, use a 'default' statement instead of the init space.

default player = Player("Derp", 100, 50)

This simple change make the objects parsed by the save system.
That's true for whatever object (like list of items and so on) you're planning to use.

And that's all.

As for doubling objects... https://www.renpy.org/dev-doc/html/save ... NoRollback
(that's mean item duplication is alreadyy avoided by renpy and you must use a special instance to MAKE item duplications by rollbacks... In the end, your code is redundant as long objects are default).

In the end I should also say that binding an item to a dictionary key when you can directly use the reference is... Well, it look like old lovely BASIC, but is bad pythonese.

default gun = Item(**)
default inv = [gun]

That will incredibly simplify your other routines.

There's a lot of customization you can do too. For example in stats and use of items. If you'll use a class for stats you can abstract the item use and the entire code will last... 4 lines?
Try for, it can be very fun.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

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 code item and Load/Save bug

#3 Post by sculpteur »

gas wrote: Sun Dec 27, 2020 9:51 pm When you create objects, use a 'default' statement instead of the init space.
In the end, your code is redundant as long objects are default).
Great, really good to know, thank you. I read you message and I'm working on it since.

I tried it a lot but, as I'am not really familiar with the defaut statement,I got a lot of synthax error that I don't understand and I had to go back to be sure I don't mess up with my code. The thing is, I have a lot of line I need to change and I would like to do it the cleaniest way possible.

So just a little bit direction to how I should make it all "default" and not "init / init -1 / init python" will be great if you can.

There is the code I need to change (I think?) :

Here in init -1 python it's suppose to be like a library or something I guess. But If I change it in init python he don't like that because "Item" (with a capital letter) is define after.

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

    class Player(renpy.store.object):
        def __init__(self, name, max_main_health=0, max_main_hunger=0, max_main_thirst=0, max_main_energy=0, max_main_sleep=0, max_main_moral=0, max_main_tension=0, element=None):
            self.name=name
            self.max_main_health=max_main_health
            self.main_health=max_main_health
            self.max_main_hunger=max_main_hunger
            self.main_hunger=max_main_hunger
            self.max_main_thirst=max_main_thirst
            self.main_thirst=max_main_thirst
            self.max_main_energy=max_main_energy
            self.main_energy=max_main_energy
            self.max_main_sleep=max_main_sleep
            self.main_sleep=max_main_sleep
            self.max_main_moral=max_main_moral
            self.main_moral=max_main_moral
            self.max_main_tension=max_main_tension
            self.main_tension=max_main_tension
            self.element=element
    player = Player("Derp", 100, 50)

    class Item(store.object):
        def __init__(self,
            name,
            player=None,
            cost=0,
            main_health=0,
            main_hunger=0,
            main_thirst=0,
            main_energy=0,
            main_sleep=0,
            main_moral=0,
            main_tension=0,
            element="",
            image="",
            trashable=True,
            usable=True):

            self.name=name
            self.player=player # which character can use this item?
            self.cost=cost # how much does it cost in shops?
            self.main_health = main_health # does this item modify health?
            self.main_hunger = main_hunger # does this item modify hunger?
            self.main_thirst = main_thirst # does this item modify thirst?
            self.main_energy = main_energy # does this item modify energy?
            self.main_sleep = main_sleep # does this item modify sleep?
            self.main_moral = main_moral # does this item modify moral?
            self.main_tension = main_tension # does this item modify tension?
            self.element=element # does this item change elemental damage?
            self.image=image
            self.trashable = trashable
            self.usable= usable

        def use(self): #here we define what should happen when we use the item
            if self.main_health>0: # healing item
                player.main_health = player.main_health+self.main_health
                if player.main_health > player.max_main_health: # can't heal beyond max HP
                    player.main_health = player.max_main_health
                inventory.drop(self) # consumable item - drop after use
            elif self.main_hunger>0: # hunger restore item
                player.main_hunger = player.main_hunger+self.main_hunger
                if player.main_hunger > player.max_main_hunger: # can't increase hunger beyond max
                    player.main_hunger = player.max_main_hunger
                inventory.drop(self) # consumable item - drop after use
            elif self.main_thirst>0: # thirst restore item
                player.main_thirst = player.main_thirst+self.main_thirst
                if player.main_thirst > player.max_main_thirst: # can't increase thirst beyond max
                    player.main_thirst = player.max_main_thirst
                inventory.drop(self) # consumable item - drop after use
            elif self.main_moral<0: # moral gain item
                player.main_moral = player.main_moral+self.main_moral
                if player.main_moral > player.max_main_moral: # can't increase moral beyond max
                    player.main_moral = player.max_main_moral
            elif self.main_moral<0: # moral down item
                player.main_moral = player.main_moral-self.main_moral
                if player.main_moral < 0: # can't decrease moral beyond zero
                    player.main_moral = 0
            else:
                player.element=self.element #item to change elemental damage; we don't drop it, since it's not a consumable item


    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:
                item.use()

        def has_space(self):
            return len(self.items) < self.spaces


    class Container(store.object):
        def __init__(self, allowed=[], allow_all=False, spaces = 4):
            self.items = []
            self.allowed = allowed
            self.allow_all = allow_all
            self.spaces = spaces

        def add(self, item):
            if self.allow_all or item in self.allowed:
                self.items.append(item)
                return True
            else:
                return False

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

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

        def clear_container_found(self, item):
            self.items.remove(item)

        def has_space(self):
            return len(self.items) < self.spaces

    def move_item(from_container, to_container, item):
        if to_container.add(item):
            if not from_container.drop(item):
                print("", "Failed to drop [item.name]!")
            else:
                print("", "Item moved")
        else:
            if to_container.has_space():
                print("", "Failed to add [item.name] for some reason.")
            else:
                print("", "Failed to add [item.name]: out of space!")

Code: Select all

init:

############ Quest_Item_Tooltip
    image information = Text("INFORMATION", style="tips_top")
    image tooltip_inventory_weapon_revolver=LiveComposite((665, 73), (3,0), Text("Revolver", style="tips_top"), (185,25), Text("My old python revolver. Usefull in many situation.", size=24))
    image tooltip_inventory_tools=LiveComposite((665, 73), (3,0), Text("Tools", style="tips_top"), (185,25), Text("Some tools, useful to repair stuff", size=24))
############ Generic_Item_Tooltip
# Food & Water
    image tooltip_inventory_gift_apple=LiveComposite((665, 73), (3,0), Text("{space=15}Red Apple", style="tips_top"), (185,25), Text("A red apple. Can be use as a gift. \n{size=-5}Perishable : Yes {space=15} Hunger : {color=#00ff00}- 1{/color}{/size}", size=24))
    image tooltip_inventory_foodfruit_1=LiveComposite((665, 73), (3,0), Text("Oranges", style="tips_top"), (185,25), Text("Some fresh oranges. \n{size=-5}Perishable : Yes {space=15} Hunger : {color=#00ff00}- 3{/color}{/size}", size=24))

Code: Select all

init python:

    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),
        "Teddybear": Item("Teddybear", image="gui/item_icon_teddybear.png", trashable=False, usable=False),
        "Towel": Item("Towel", image="gui/item_icon_towel.png", trashable=True, usable=False),
        "Soap": Item("Soap", image="gui/item_icon_soap.png", trashable=True, usable=False),
        "Sponge": Item("Sponge", image="gui/item_icon_sponge.png", trashable=True, usable=False),
        }

    inventory = Inventory()
    container = Container()
    container_null = Container([items["Null_Item"]])
    inventory_big = Container("Container", allow_all=True)
    container1 = Container([items["Ducktape"], items["Tools"]])
    container2 = Container([items["Teddybear"]])
    container3 = Container([items["Towel"], items["Sponge"], items["Bassin"], items["Soap"]])
    container4 = Container([items["Manche"]])
    container5 = Container()
    container_gift_1 = Container([items["RedApple"]])
    container_food = Container([items["FoodRationSmall"], items["FoodRationBig"], items["FoodCan"], items["Rice"]])
    container_gaztank = Container([items["Butane"]])
    container_generator = Container([items["Gasoline"]])
    container_cloth = Container([items["Clothes"], items["SewingKit"], items["Fabric"]])
    container_toiletries = Container([items["Clothes"]])
    container_alcohol= Container([items["WineCalifornian"], items["WineItalian"], items["WineFrench"]])
    container_fillwater = Container([items["WaterBottleEmpty"]])
    container_found = Container("Container", allow_all=True)
    container_trash = Container("Container", allow_all=True)
    
# Container space
    inventory.spaces = 4
    inventory_big.spaces = 14
    container_found.spaces = 13
    container_food.spaces = 1
    container_trash.spaces = 1
    
# Inventory Interface Button
    inv_button_sensitive = False
    invbig_button_sensitive = False
    inv_button_show = False
    show_inventory = False
    show_inventory_addon = False
    desactivate_inventory_addon = False

Code: Select all

label start:

# VARIABLES : GENERAL MECHANICS
$ time_hour = 8
$ time_minute = 15
$ time_hour_display = "8"
$ time_minute_display = "15"
$ time_day = 1
$ food_storage = renpy.random.randint(20,25)
$ food_storage_max = 100
$ cloth_storage = 0
$ cloth_storage_max = 100
$ gasoline_storage = renpy.random.randint(15,20)
$ gasoline_storage_max = 100
$ gaztank_storage = 0
$ gaztank_storage_max = 100
$ toiletries_storage = 0
$ toiletries_storage_max = 100
$ alcohol_storage = renpy.random.randint(40,50)
$ alcohol_storage_max = 100

# VARIABLES : PROGRESSION MARKER SHORT
$ progression_general_havebeendone = False
$ progression_general_havebeendone1 = False
$ progression_general_havebeendone2 = False
$ progression_general_havebeendone3 = False
$ progression_general_havebeendone4 = False
$ progression_general_havebeendone5 = False
$ progression_general_havebeendone6 = False
$ progression_general_havebeendone7 = False
$ progression_examen_2A = False
$ progression_examen_2B = False
$ progression_examen_3A = False
$ progression_examen_3B = False
$ progression_examen_3C = False

# VARIABLES : MAIN CHARACTER STAT
$ player = Player("Derp", 100, 50)
$ player.main_health = 100
$ player.main_hunger = 10
$ player.main_thirst = 10
$ player.main_energy = 10
$ player.main_sleep = 10
$ player.main_moral = 10
$ player.main_tension = 10
$ main_hunger = 100
$ main_thirst = 100
$ main_energy = 100
$ main_health = 100
$ main_moral = 0
$ main_tension = 0
$ main_hunger_max = 100
$ main_thirst_max = 100
$ main_energy_max = 100
$ main_health_max = 100
$ main_moral_max = 100
$ main_tension_max = 100
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: Python code item and Load/Save bug

#4 Post by Remix »

Your issue might be stemming from using a mutator within the init of Container...

Code: Select all

    class Container(store.object):
        def __init__(self, allowed=[], allow_all=False, spaces = 4):
            # allowed has a default of empty list
            # list is a mutatable sequence so that default becomes shared amongst instances of the class
            # If an instance passes in ["dog"] the class then defaults to allowed=["dog"]
            # which can get real messy and hard to debug

It is quite a common Python gotcha

Better:

Code: Select all

    class Container(store.object):
        def __init__(self, allowed=None, allow_all=False, spaces = 4):
            self.allowed = allowed or []
Not sure if it will fix your issue... Best to fix that anyway
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 code item and Load/Save bug

#5 Post by sculpteur »

Not sure if it will fix your issue... Best to fix that anyway
Thank for fixing this issue, i've done it but saddly that's didn't fix my initial problem.

As "gas" told me before, the issue is suppose to be simple because its related to the fact I didn't use the default statement for my inventory system.

I just need to modify it to use "default" and not "init" but, like I said before, I don't know what's the code sythax I should use to modify that and I don't know which part need to be changed with the default statement.

If someone could just tell me how to modify it that will help me a lot in order to modify everything without messing up my code.

Thank you !
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 code item and Load/Save bug

#6 Post by sculpteur »

So Anyone can guide me a little on how should I define my variables / Item with the default statement and which one should I focus on to avoid this Item bug duplication on load 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.

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 code item and Load/Save bug

#7 Post by sculpteur »

And I know there is different chronological time to define variables. Init - x / init / default / init + x but I still can't figure out what's the best way to define it without the SAVE/LOAD bug
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: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python code item and Load/Save bug

#8 Post by philat »

It's literally just

default time_hour = 8
default time_minute = 15

etc., without indentation, anywhere in the script.

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 code item and Load/Save bug

#9 Post by sculpteur »

Thank you philat, but I lacked clarity about the difficulty in question. For my variables who are define with the python line which begin by "$" I had figuring it out, like you said, it's quite simple. If I put this code section where I define I this variable line by line, it was only to be sure you guys understood the inventory system I'm trying to fix as a whole.

The difficulty is for part where a whole section of code is in python, like :

Code: Select all

init python:

    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),
        "Teddybear": Item("Teddybear", image="gui/item_icon_teddybear.png", trashable=False, usable=False),
        "Towel": Item("Towel", image="gui/item_icon_towel.png", trashable=True, usable=False),
        "Soap": Item("Soap", image="gui/item_icon_soap.png", trashable=True, usable=False),
        "Sponge": Item("Sponge", image="gui/item_icon_sponge.png", trashable=True, usable=False),
        }

    inventory = Inventory()
    container = Container()
    container_null = Container([items["Null_Item"]])
    inventory_big = Container("Container", allow_all=True)
    container1 = Container([items["Ducktape"], items["Tools"]])
Or

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

    class Player(renpy.store.object):
        def __init__(self, name, max_main_health=0, max_main_hunger=0, max_main_thirst=0, max_main_energy=0, max_main_sleep=0, max_main_moral=0, max_main_tension=0, element=None):
            self.name=name
            self.max_main_health=max_main_health
            self.main_health=max_main_health
            self.max_main_hunger=max_main_hunger
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 code item and Load/Save bug

#10 Post by sculpteur »

Neither mind, my bad. I think I figure it out. I still need some more testing to be sure but I choose to not touch the Python class and sub-class and just change this part like that :

Code: Select all

default items = {
        "Null_Item": Item("Null_Item", image="gui/item_icon_tools.png"),
        "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),

Code: Select all

default container_found = Container("Container", allow_all=True)
default container_trash = Container("Container", allow_all=True)
default inventory.spaces = 4
default inventory_big.spaces = 14
default container_found.spaces = 13
and I remove the "init python:"

I was overthinking this because I got afraid about changing the Python classes which make my inventory system working ^^

Thank you
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: Ahrefs [Bot], Google [Bot]