Freezing game until screen hidden

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
RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Freezing game until screen hidden

#1 Post by RewindTheGame »

This may be a simple question, but it's causing me enough of a headache that I'm sure somebody here can answer it in 5 seconds and save my sanity!

Essentially, I have a screen which plays a complex board game. If the player wins the game, the global variable lWonGame is set to True. This screen can be called as a menu from the main menu in order that the player can play the game casually whenever they like, and this works perfectly well calling it with ShowMenu().

The problem is when I want the game to appear within the main game itself. I want to have something like this:

Code: Select all

show screen boardgame
if lWonGame:
	"Congratulations. Access to central computer granted"
else:
	"Access Denied."
This doesn't work. The code appears to continue to evaluate even while the screen is displayed, instead of halting until the screen code returns as I had expected. The screen is displayed and then "Access Denied" is immediately displayed before the player has even played the board game. So how do I display a screen and tell the code to stop executing until the screen executes a return statement at which point the next line of code runs?

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

Re: Freezing game until screen hidden

#2 Post by Ocelot »

It is hard to tell for sure, without knowing if you used any interaction-stopping code in your minigame, but usually

Code: Select all

call screen boardgame
is enough.
< < insert Rick Cook quote here > >

RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Freezing game until screen hidden

#3 Post by RewindTheGame »

Yeah, that's what I figured. I'm not quite sure what I've done wrong somewhere, but show screen seems to drop straight through and call screen doesn't even show screen at all. Or the other way around - I'm not in front of my Mac right now. I'm sure I've just done something silly somewhere. If anyone has a sudden brainstorm in the meantime, though, please shout it in my direction :).

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Freezing game until screen hidden

#4 Post by m_from_space »

You could just try to create a very basic screen using both "call screen" within the game and the ShowMenu() option within the main menu to figure out what's going on. I assume something inside the boardgame screen is fishy.

We may need to see some parts of the boardgame code.

RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Freezing game until screen hidden

#5 Post by RewindTheGame »

I'm sure I must be doing something wrong based on 40 years of programming in different languages, but essentially what I'm doing is this:

In the main script code:

Code: Select all

$close_serendipity=False
call screen serendipity
while close_serendipity=False:
    ""
... continue game here
I know the whole while loop shouldn't be necessary, but as I say the game seems to just carry on once the screen is displayed rather than pausing until the screen is hidden as I would expect it to do so the only way to stop this is to set a variable in the screen which gets set when the player presses the "close" button.

The screen itself is just a series of images, image buttons, frames and the like - nothing special. The image buttons correspond to the squares on the board and when pressed jump to a routine that moves all the pieces and updates the array holding the board layout.Theres a close button which simply hides the screen, and since the screen is sitting on top of the game I had assumed this would simply return to the game and carry on with the next line. What it actually does is stop the entire game and return to the main menu. I have to say, I'm currently completely lost.

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

Re: Freezing game until screen hidden

#6 Post by Ocelot »

Ok, since you do have a programming bacground, that would be sligthly easier to explain.

call screen does not do what you expect when you hear "call". There is no call stack involved, there is no new frame created... What it does, it shows screen as transient (which is shorthand for autohiding screen) and forces an interaction (which is a shorthand for "pause script execution and force user to do something with the game"). If you jump, it would (1) stop an interaction (which will hide the screen and unpause script execution) and (2) it will take you out of currently executing statement and place you whenever you jumped to.

I suspect that there is an another call screen statement in that setup routine and either a "return" (which will return to main menu if called with empty RenPy script call stack) or execution simply falls to the end of file (which returns you to the main menu too)
< < insert Rick Cook quote here > >

RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Freezing game until screen hidden

#7 Post by RewindTheGame »

Interesting. That does help quite a lot, thanks. Sometimes I wonder why different languages don't just stick to the same terminology rather than trying to be "cool" and coming up with their own commands you have to relearn. Never understood what was wrong with "Goto" and "Gosub" in BASIC myself - I mean, that's essentially what "Jump" and "Call" are, right?

Anyway, thanks Ocelot. I'm sure there's an unwanted Return in there somewhere. The screen definition does end at the end of it's relevant source file, but surely that in itself isn't enough to return to the menu - I have other screens which end at the end of a file and they don't do the same thing.

Right, I'm going to grab a coffee and hopefully come back to this with a clear head...

RewindTheGame
Regular
Posts: 62
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Freezing game until screen hidden

#8 Post by RewindTheGame »

Just to keep you up to date, it's all working now. Not sure how much I like having to force something into working by excessive fiddling about rather than things just working as expected, but hey - you gotta roll with the punches :)

JuanCollett
Newbie
Posts: 1
Joined: Mon Feb 27, 2023 9:38 am
Contact:

Re: Freezing game until screen hidden

#9 Post by JuanCollett »

Thanks for the help. And if anyone over here is searching for a site online where you can find Crazy Luck casino login and review then visit https://casinosanalyzer.com/online-casi ... casino.com here to find those sites with reviews. And also you will find a lot of amazing offers over there.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]