renpy.restart_interaction AFTER a Return?

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
User avatar
lking22
Regular
Posts: 45
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

renpy.restart_interaction AFTER a Return?

#1 Post by lking22 » Tue Feb 18, 2020 10:28 pm

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.
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2848
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: renpy.restart_interaction AFTER a Return?

#2 Post by Imperf3kt » 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
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter

User avatar
lking22
Regular
Posts: 45
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: renpy.restart_interaction AFTER a Return?

#3 Post by lking22 » Tue Feb 18, 2020 11:36 pm

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?
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2848
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: renpy.restart_interaction AFTER a Return?

#4 Post by Imperf3kt » Tue Feb 18, 2020 11:53 pm

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
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter

User avatar
lking22
Regular
Posts: 45
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: renpy.restart_interaction AFTER a Return?

#5 Post by lking22 » Tue Feb 18, 2020 11:58 pm

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.
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

User avatar
gas
Miko-Class Veteran
Posts: 623
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: renpy.restart_interaction AFTER a Return?

#6 Post by gas » Wed Feb 19, 2020 1:21 am

Tried this with no avail?

imagebutton idle pic action [SetVariable("item", item), renpy.restart_interaction, Return()]
10 ? "RENPY"
20 GOTO 10

RUN

User avatar
lking22
Regular
Posts: 45
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: renpy.restart_interaction AFTER a Return?

#7 Post by lking22 » Wed Feb 19, 2020 1:23 am

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.
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

User avatar
Alex
Lemma-Class Veteran
Posts: 2433
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: renpy.restart_interaction AFTER a Return?

#8 Post by Alex » 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

User avatar
lking22
Regular
Posts: 45
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: renpy.restart_interaction AFTER a Return?

#9 Post by lking22 » Wed Feb 19, 2020 7:07 pm

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.
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

User avatar
Alex
Lemma-Class Veteran
Posts: 2433
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: renpy.restart_interaction AFTER a Return?

#10 Post by Alex » 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

User avatar
lking22
Regular
Posts: 45
Joined: Sun Dec 03, 2017 3:33 am
Projects: Grey Feather
itch: freefall-games
Contact:

Re: renpy.restart_interaction AFTER a Return?

#11 Post by lking22 » Wed Feb 19, 2020 7:29 pm

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?
Releases:
Image

Current projects:
In the Ashes of Dawn
Split Psyche
Savestate Gambit

User avatar
Alex
Lemma-Class Veteran
Posts: 2433
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: renpy.restart_interaction AFTER a Return?

#12 Post by Alex » Thu Feb 20, 2020 2:20 pm

You can use the screen you have, but show it with Show action to stay in a game context.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]