Screeen not Refreshing after Shift + R

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
DewyNebula
Newbie
Posts: 15
Joined: Sun Apr 21, 2024 10:57 am
Contact:

Screeen not Refreshing after Shift + R

#1 Post by DewyNebula »

Hello, I got my inventory screen working how I wanted it to, but it won't update in a current save if I Shift + R. When I edit dialogue, I can use the same save and see the changes, but my inventory screen is not the same. I have to start a new save to see my updated code. Why is this? Is there a fix? My current code is below - feel free to suggest edits to it (still green to coding):

Code: Select all

# Python to define MC stat variables
label mc_stats_inventory:
    # MC Health and Willpower amount
    $ mc_bonus_hp = skill3_points
    $ mc_hp_max = 50 + mc_bonus_hp
    $ mc_hp = mc_hp_max
    $ mc_bonus_wp = skill5_points
    $ mc_wp_max = 50 + mc_bonus_wp
    $ mc_wp = mc_wp_max
default mc_hp = 50
# Inventory python code
init python:
    # What the items can do (add and remove)
    class Inventory():
        def __init__(self, items, no_of_items):
            self.items = items
            self.no_of_items = no_of_items
        # Add the item - to add item to inventory use "$ inventory.add_item(item)"
        def add_item(self, item):
            self.items.append(item)
            self.no_of_items += 1
        # Remove the item - to remove item from inventory use "$ inventory.remove_item(item)"
        def remove_item(self, item):
            self.items.remove(item)
            self.no_of_items -= 1
    # How the items show (image and effect)
    class InventoryItem():
        def __init__(self, image, description, action):
            self.image = image
            self.description = description
            self.action = action
# MC inventory open
screen mc_inventory():
    add "bg-inventory"
    modal True
    # Close inventory Button
    imagebutton auto "button-check-%s":
        align (0.5, 0.05)
        action [Hide(), ToggleScreen("mc_hud")]
    hbox:
        align(0.08, 0.25)
        textbutton "Items":
            action Show("mc_inventory_items")
        textbutton "Weapons":
            action NullAction()
        textbutton"Special":
            action NullAction()
screen mc_inventory_items():
    # Inventory Grid
    grid 4 16:
        spacing 10
        align(0.04, 0.3)
        for item in inventory.items:
            frame:
                maximum(0, 0)
                imagebutton:
                    idle [item.image]
                    action [item.action, RemoveFromSet(inventory.items, item)]
                    tooltip [item.description]
        $ tooltip = GetTooltip()
    if tooltip:
        nearrect:
            focus "tooltip"
            prefer_top True 
            text tooltip
# Inventory starting space (None)
default inventory = Inventory([],0)
# Bandages item
default bandages = InventoryItem("item-bandages", "+25 Health", Function(bandages_effect, 25))
init python:
    def bandages_effect(amount):
        store.mc_hp += 25
        if mc_hp > mc_hp_max:
            store.mc_hp = min(mc_hp_max, mc_hp + amount)

jeffster
Veteran
Posts: 440
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Screeen not Refreshing after Shift + R

#2 Post by jeffster »

Note that with Shift-R you "turn ON" the mode that refreshes the data every time the source files change.
Hence you press Shift-R only once, and the game will be reloaded automatically each time the code changes. (Until you press Shift-R again).
It means if you press Shift-R twice, you turn the refreshing mode off, and have to press Shift-R again to reload new data.

Besides, I suspect that "init" blocks might be not refreshable, because they run before all those game loads and reloads (meaning, they might be unaffected by reloads).
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

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

Re: Screeen not Refreshing after Shift + R

#3 Post by Ocelot »

jeffster wrote: Thu May 09, 2024 8:18 pm Besides, I suspect that "init" blocks might be not refreshable, because they run before all those game loads and reloads (meaning, they might be unaffected by reloads).
Shift+R reloads make use of neat undocumented functionality which utterly restarts the game, including reloading and rerunning all script, including init blocks.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: giorgi1111