Page 1 of 1

renpy.restart_interaction AFTER a Return?

Posted: Tue Feb 18, 2020 10:28 pm
by lking22
I have an inventory screen where a player can select an item, and that item is then 'in use'. I would like to have it so that new options show up in the choice screen when certain items are in use, which is working... mostly. It detects the in use item, but only if I use it at least one interaction before the choice screen. I'd like to be able to refresh the choice screen when exiting the inventory menu so that the new choice shows up even if the item wasn't in use before that screen.
So far it looks like 'renpy.restart_interaction' is my best bet, but I can't figure out how to get it to run when selecting and item, AFTER returning to the game. Putting it before just locks up the whole game whenever I entire the inventory screen.
Sorry about the lack of details on this one, it's sort of doing my head in and I don't even know where to start looking right now, or if I'm even on the right track with the functions I need to use.

Re: renpy.restart_interaction AFTER a Return?

Posted: Tue Feb 18, 2020 11:27 pm
by Imperf3kt
Have you tried setting the selected item to the _return variable via using Return(item or string) as an action

Re: renpy.restart_interaction AFTER a Return?

Posted: Tue Feb 18, 2020 11:36 pm
by lking22
Imperf3kt wrote: Tue Feb 18, 2020 11:27 pm Have you tried setting the selected item to the _return variable via using Return(item or string) as an action
Sorry, I might just be being dumb (or sleep-deprived) but I don't really know what that means?

Re: renpy.restart_interaction AFTER a Return?

Posted: Tue Feb 18, 2020 11:53 pm
by Imperf3kt
I'm assuming this is some kind of inventory, right?
How are you currently working out which item is selected?

I was suggesting you make use of the return function as documented here.
https://www.renpy.org/doc/html/screen_a ... tml#Return

Re: renpy.restart_interaction AFTER a Return?

Posted: Tue Feb 18, 2020 11:58 pm
by lking22
Yeah, it's an inventory screen. Right now it's like this:

Code: Select all

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

    inv_page = 0 # initial page of teh inventory screen
    item = None
    class Player(renpy.store.object):
        def __init__(self, name, max_hp=0, max_mp=0, element=None):
            self.name=name
            self.max_hp=max_hp
            self.hp=max_hp
            self.max_mp=max_mp
            self.mp=max_mp
            self.element=element
    player = Player("Derp", 100, 50)

    class Item(store.object):
        def __init__(self, name, player=None, hp=0, mp=0, element="", image="", cost=0):
            self.name = name
            self.player=player # which character can use this item?
            self.hp = hp # does this item restore hp?
            self.mp = mp # does this item restore mp?
            self.element=element # does this item change elemental damage?
            self.image=image # image file to use for this item
            self.cost=cost # how much does it cost in shops?

    class Inventory(store.object):
        def __init__(self, money=10):
            self.money = money
            self.items = []
        def add(self, item): # a simple method that adds an item; we could also add conditions here (like check if there is space in the inventory)
            self.items.append(item)
        def drop(self, item):
            self.items.remove(item)
        def buy(self, item):
            if self.money >= item.cost:
                self.items.append(item)
                self.money -= item.cost
    showitems = True
    
screen inventory:
    tag menu
    use game_menu(_("Inventory"), scroll="viewport"):
        style_prefix "inventory"
        $ i = 0
        $ sorted_items = sorted(inventory.items, key=attrgetter('element'), reverse=True)
        vpgrid:
            cols 3
            spacing gui.slot_spacing
            side_xalign 0.5
            for item in sorted_items:
                $ pic = item.image
                imagebutton idle pic action [SetVariable("item", item), Return()]
The variable 'item' indicates which item is in use. The choice menu is really basic:

Code: Select all

menu:
        "Yes":
            $ persistent.tw = True
        "No":
            $ persistent.tw = False
        "A third option" if item == Storybook:
            pass
It works, but only if the item is selected before the choice menu is shown. I would really like for the player to be able to pause, select an item, and then have the new option show up when they unpause.

Re: renpy.restart_interaction AFTER a Return?

Posted: Wed Feb 19, 2020 1:21 am
by gas
Tried this with no avail?

imagebutton idle pic action [SetVariable("item", item), renpy.restart_interaction, Return()]

Re: renpy.restart_interaction AFTER a Return?

Posted: Wed Feb 19, 2020 1:23 am
by lking22
gas wrote: Wed Feb 19, 2020 1:21 am Tried this with no avail?

imagebutton idle pic action [SetVariable("item", item), renpy.restart_interaction, Return()]
No, it doesn't seem to have any effect.

Re: renpy.restart_interaction AFTER a Return?

Posted: Wed Feb 19, 2020 2:59 pm
by Alex
Try to name your in-game menu, store its name in variable, jump to this menu if your inventory screen was opened while in menu.

viewtopic.php?f=8&t=57948&p=524422#p524422
https://www.renpy.org/doc/html/menus.html

Re: renpy.restart_interaction AFTER a Return?

Posted: Wed Feb 19, 2020 7:07 pm
by lking22
Alex wrote: Wed Feb 19, 2020 2:59 pm Try to name your in-game menu, store its name in variable, jump to this menu if your inventory screen was opened while in menu.

viewtopic.php?f=8&t=57948&p=524422#p524422
https://www.renpy.org/doc/html/menus.html
Using Jump looks like it works at first, but turns out it's still in the 'pause screen' for lack of a better word. If I hit esc while in the 'updated' menu it goes right back to the old version without the updated options.

Re: renpy.restart_interaction AFTER a Return?

Posted: Wed Feb 19, 2020 7:23 pm
by Alex
How do you show your inventory screen - using ShowMenu action? If so change it to Show action.

https://www.renpy.org/doc/html/screen_a ... l#ShowMenu
https://www.renpy.org/doc/html/screen_actions.html#Show

Re: renpy.restart_interaction AFTER a Return?

Posted: Wed Feb 19, 2020 7:29 pm
by lking22
Alex wrote: Wed Feb 19, 2020 7:23 pm How do you show your inventory screen - using ShowMenu action? If so change it to Show action.

https://www.renpy.org/doc/html/screen_a ... l#ShowMenu
https://www.renpy.org/doc/html/screen_actions.html#Show
The inventory screen uses the game menu, the same way a save or load screen does. Do I need to build a whole new screen for it instead to make the show thing work?

Re: renpy.restart_interaction AFTER a Return?

Posted: Thu Feb 20, 2020 2:20 pm
by Alex
You can use the screen you have, but show it with Show action to stay in a game context.