Game "Loop" and ui.interact

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
olddog
Newbie
Posts: 18
Joined: Sun Dec 30, 2018 11:27 am
Projects: Kismet, a TF/TG game
Contact:

Game "Loop" and ui.interact

#1 Post by olddog »

So, for this game I'm making, it's a pretty basic thing where you can click around to go places - in rooms, to a map, etc...

I found code that does this (after I trimmed it down for what I needed and added some things):

Code: Select all

init python:
    class World(object):
        def __init__(self):
            # Initialize World class variables
            self.oldScreen = ""
            # This will hold the previous screen
        def screen_loop(self, shownScreen):
            # The wait (event) loop
            if self.oldScreen != "":
                # Make sure there's an old screen first.
                renpy.hide_screen(self.oldScreen)
                # Hide the previous screen.
            renpy.show_screen(shownScreen)
            # Show the passed scsreen
            self.oldScreen = shownScreen
            # Store the currently used screen
            renpy.show_screen("scr_details")
            # Add the header
            while True:
                result = ui.interact()
In the game, I jump to a label that is named for a location (like main_character_bedroom). Then I call:

Code: Select all

$ world.screen_loop("scr_main_character_bedroom")
Which hides any previous screen and then loads up the screen containing all the sprites and images for the room along with the header and such. I can also use the block to test for conditions like time of day or what not.

The game then pauses and waits for the user to click on something. At the end of that interaction, I jump right back to main_character_bedroom which executes the "screen_loop" code above and the game waits for the next thing.

It's working well for me but I guess I want to check if that's the best way to do it. And, if not, whether there's a better way.

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Game "Loop" and ui.interact

#2 Post by rames44 »

Seems to me that that is a kind of artificial way to make a screen modal and wait for a click. Why not just “call” the screen, and have the clickable elements just Return() when it’s time to continue? You could still use a variable to decide what screen to call next, but you don’t have to show/hide (Return hides automatically) and you don’t need the UI.interact() loop.

Just my $0.02...

olddog
Newbie
Posts: 18
Joined: Sun Dec 30, 2018 11:27 am
Projects: Kismet, a TF/TG game
Contact:

Re: Game "Loop" and ui.interact

#3 Post by olddog »

rames44 wrote: Sat Jan 12, 2019 12:30 pm Seems to me that that is a kind of artificial way to make a screen modal and wait for a click. Why not just “call” the screen, and have the clickable elements just Return() when it’s time to continue? You could still use a variable to decide what screen to call next, but you don’t have to show/hide (Return hides automatically) and you don’t need the UI.interact() loop.

Just my $0.02...
I got that to work with a tiny bit of modification and it seems to be doing well, thank you!

Post Reply

Who is online

Users browsing this forum: Google [Bot]