Event triggered on clicking the X(close) button?

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
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Event triggered on clicking the X(close) button?

#1 Post by ChroniclerOfLegends »

Hello, I have a mini game that runs through a creator defined displayable, and it is working well.

However I have run into a problem.
The player can pause the minigame and exit it by pressing ESC while on the minigame screen.
However, if the player clicks the X(close) button at the top of the window, the game does not pause and it is overlayed with the Are you sure you want to quit screen.

This all works correctly except I want to send my minigame a message to pause immediately so that the user can make their choice without the game screen still moving in the background.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Event triggered on clicking the X(close) button?

#2 Post by xavimat »

I've tried using the special label "quit", but it's called after the confirm screen.
The only solution I can think of is an action in the Confirm Screen to stop the minigame, for example, SetVariable() or Function().

Code: Select all

screen confirm(message, yes_action, no_action):

    on "show" action Function("stopmyminigame")   ## <<-- Add this line
    on "show" action SetVariable("minigamestopped", True)   ## <<-- Or this one

    # ... The rest of the screen...
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Re: Event triggered on clicking the X(close) button?

#3 Post by ChroniclerOfLegends »

Thank you, that got me in the right direction.
I added this line to my confirm screen and it works great:

Code: Select all

on "show" action SetField(game, 'paused', True)
My minigame is defined as a creator defined displayable, and it is paused my toggling the self.paused variable.

User avatar
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Re: Event triggered on clicking the X(close) button?

#4 Post by ChroniclerOfLegends »

Uh oh... I ran into a different problem. Now an error is thrown when I try and click X when the minigame is not running because an instance of game does not exist.

If this was straight python I would fix this by:

Code: Select all

try:
  on "show"....
except:
  pass
I am not quite sure how I would do try/except in screen language...
Is there a way to use an if statement to check if variable game exists first?

EDIT:
Got it, enclosed on 'show' inside of an if (game != None):

Post Reply

Who is online

Users browsing this forum: Google [Bot]