A new screen question

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
Karasu_Noir
Regular
Posts: 45
Joined: Sun May 11, 2008 12:24 am
Location: Somwhere dark so I can relax
Contact:

A new screen question

#1 Post by Karasu_Noir »

Scrolled through the renpy cookboks and tutorials, and wondering how to create an in-game ui button which when it is clicked,it brings up a new label (I plan to make it the label for viewing explanations, so that the players can look at it anytime when they forget something. My game has many japanese terms.) Can you help?
A life is a life, there's no need to rush anything.
Just sit back and relax.
But don't take too long.
.............Or darkness will eat you.

Chansel
Veteran
Posts: 249
Joined: Sat May 01, 2010 6:11 pm
Projects: School's Out! -- A GxB or GxG VN/Dating Sim
Location: The Netherlands, Noord-Brabant
Contact:

Re: A new screen question

#2 Post by Chansel »

Try editing this to your liking (it's what I'm using for a 'stats' button):

Code: Select all

ui.hbox(xpos=369, ypos=561, xanchor='left', yanchor='top')
ui.imagebutton("idle.png", "hover.png", clicked=ccinc("explanations"), xminimum=62, yminimum=36)
ui.close()
"explanations" would be the name of the label in this case :)
I'm not 100% sure this is the best way to do it, but it works =D
Xx
Image ~ A GxB or GxG Visual Novel/Dating Sim

Karasu_Noir
Regular
Posts: 45
Joined: Sun May 11, 2008 12:24 am
Location: Somwhere dark so I can relax
Contact:

Re: A new screen question

#3 Post by Karasu_Noir »

Code: Select all

I'm sorry, but an exception occured while executing your Ren'Py
script.

NameError: name 'ccinc' is not defined

While running game code:
 - script at line 876 of D:\renpy-6.10.2\Hikaru_Wish/game/script.rpy
 - python at line 876 of D:\renpy-6.10.2\Hikaru_Wish/game/script.rpy.
A life is a life, there's no need to rush anything.
Just sit back and relax.
But don't take too long.
.............Or darkness will eat you.

Chansel
Veteran
Posts: 249
Joined: Sat May 01, 2010 6:11 pm
Projects: School's Out! -- A GxB or GxG VN/Dating Sim
Location: The Netherlands, Noord-Brabant
Contact:

Re: A new screen question

#4 Post by Chansel »

Oh, oops :P Sorry 'bout that.
I'm using the on screen buttons cookbook thing which defines ccinc ^^" http://www.renpy.org/wiki/renpy/doc/coo ... _Game_Menu
You actually might want to take a look at that :)
Anyway, replace it with this:

Code: Select all

renpy.curried_call_in_new_context("explanations")
and it should work.
Image ~ A GxB or GxG Visual Novel/Dating Sim

Karasu_Noir
Regular
Posts: 45
Joined: Sun May 11, 2008 12:24 am
Location: Somwhere dark so I can relax
Contact:

Re: A new screen question

#5 Post by Karasu_Noir »

So, in the script at the point when I want to button to appear...

Code: Select all

 
    himiko "You can check the dictionary every time."
    $ ui.hbox(xpos=369, ypos=561, xanchor='left', yanchor='top')
    $ ui.imagebutton("idle.png", "hover.png", clicked = renpy.curried_call_in_new_context("explanations"), xminimum=62, yminimum=36)
    $ ui.close()
    himiko "Good." ## ui.umagebutton dissapears? Why?
   ##some more scripts
   himiko "Now I want to borrow the dictionary"
   ## The ui.image button dissapears here

But it dissapeared at the next dialouge, when himiko talks again. How do I make it appear until some point in the game?
Last edited by Karasu_Noir on Fri May 28, 2010 10:35 pm, edited 1 time in total.
A life is a life, there's no need to rush anything.
Just sit back and relax.
But don't take too long.
.............Or darkness will eat you.

Chansel
Veteran
Posts: 249
Joined: Sat May 01, 2010 6:11 pm
Projects: School's Out! -- A GxB or GxG VN/Dating Sim
Location: The Netherlands, Noord-Brabant
Contact:

Re: A new screen question

#6 Post by Chansel »

Aha. Well, that's because it's supposed to go in an init python block ^^" Which goes before your start label.
And if you want it to appear at a certain time, use a variable for that.

Code: Select all

init python:
    show_button_game_menu = False
    
    def button_game_menu():

        if show_button_game_menu:
            
            ui.hbox(xpos=281, ypos=575, xanchor='left', yanchor='top')
            ui.imagebutton("idle.png", "hover.png", clicked=renpy.curried_call_in_new_context("explanations"), xminimum=37, yminimum=22)
            ui.close()   
            
    config.overlay_functions.append(button_game_menu)    

label start:

"No button"
$ show_button_game_menu = True
"Yay, a button!"
"Extra text :)"
$ show_button_game_menu = False
"Bye, button :("
So, basically, the game starts of with the button turned off. To turn it on, set show_button_game_menu to True :) To turn it off again, set it to False.
Sorry for taking so long in helping out.. I'm still new to the whole 'helping people out' thing ^^"
Anyway, this should work =D (tested it in an empty template, just to be sure XD)
Image ~ A GxB or GxG Visual Novel/Dating Sim

Karasu_Noir
Regular
Posts: 45
Joined: Sun May 11, 2008 12:24 am
Location: Somwhere dark so I can relax
Contact:

Re: A new screen question

#7 Post by Karasu_Noir »

Code: Select all

 $ show_button_game_menu = False
   
    def button_game_menu():

        if show_button_game_menu:
           
            ui.hbox(xpos=281, ypos=575, xanchor='left', yanchor='top')
            ui.textbutton("Dictionary", clicked=renpy.curried_call_in_new_context("explanations"), xminimum=37, yminimum=22)
            ui.close()   
           
    $ config.overlay_functions.append(button_game_menu)
shows

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


On line 28 of D:\renpy-6.10.2\Hikaru_Wish/game/script.rpy: expected statement.
def button_game_menu():
    ^
A life is a life, there's no need to rush anything.
Just sit back and relax.
But don't take too long.
.............Or darkness will eat you.

Chansel
Veteran
Posts: 249
Joined: Sat May 01, 2010 6:11 pm
Projects: School's Out! -- A GxB or GxG VN/Dating Sim
Location: The Netherlands, Noord-Brabant
Contact:

Re: A new screen question

#8 Post by Chansel »

That's because you added two '$'
Just copy past everything from above the start label and it should work.
Image ~ A GxB or GxG Visual Novel/Dating Sim

Karasu_Noir
Regular
Posts: 45
Joined: Sun May 11, 2008 12:24 am
Location: Somwhere dark so I can relax
Contact:

Re: A new screen question

#9 Post by Karasu_Noir »

Hmm...

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


On line 26 of D:\renpy-6.10.2\Hikaru_Wish/game/script.rpy: expected statement.
show_button_game_menu = False
                      ^

On line 28 of D:\renpy-6.10.2\Hikaru_Wish/game/script.rpy: expected statement.
def button_game_menu():
    ^

On line 36 of D:\renpy-6.10.2\Hikaru_Wish/game/script.rpy: expected statement.
config.overlay_functions.append(button_game_menu)        
                                                         ^
A life is a life, there's no need to rush anything.
Just sit back and relax.
But don't take too long.
.............Or darkness will eat you.

Chansel
Veteran
Posts: 249
Joined: Sat May 01, 2010 6:11 pm
Projects: School's Out! -- A GxB or GxG VN/Dating Sim
Location: The Netherlands, Noord-Brabant
Contact:

Re: A new screen question

#10 Post by Chansel »

Alright, I'm lost :S
I copy pasted everything in an empty renpy files and it works fine for me...
Expected statement is usually something with identation or when there's a colon missing or something. Make sure all your identations are correct and check if you didn't accidentaly deleted a colon or something.
Image ~ A GxB or GxG Visual Novel/Dating Sim

Karasu_Noir
Regular
Posts: 45
Joined: Sun May 11, 2008 12:24 am
Location: Somwhere dark so I can relax
Contact:

Re: A new screen question

#11 Post by Karasu_Noir »

I think because I have init: so I put the code right below init:

I put init phyton: and init: in a separate place and it worked.
Thank you.

Another question, so I made a new label, how do I make it return to the scene where I clicked it before?

Code: Select all

label explanation: 
   scene bg dict
   ## Long, long explanation
   ##Want to put a button to return to the previous scene
A life is a life, there's no need to rush anything.
Just sit back and relax.
But don't take too long.
.............Or darkness will eat you.

User avatar
azureXtwilight
Megane Procrastinator
Posts: 4118
Joined: Fri Mar 28, 2008 4:54 am
Completed: Fantasia series (ROT and ROTA), Doppleganger: Dawn of The Inverted Soul, a2 (a due), Time Labyrinth
Projects: At Regime's End
Organization: Memento-Mori VNs, Team Sleepyhead
Location: Yogyakarta, Indonesia.
Contact:

Re: A new screen question

#12 Post by azureXtwilight »

Karasu_Noir wrote:I think because I have init: so I put the code right below init:

I put init phyton: and init: in a separate place and it worked.
Thank you.

Another question, so I made a new label, how do I make it return to the scene where I clicked it before?

Code: Select all

label explanation: 
   scene bg dict
   ## Long, long explanation
   ##Want to put a button to return to the previous scene
I think you don't need to do that, because the scene returns when you click at the explanation label after the long explanation is done. Maybe it is you who did something wrong.
Image

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

Re: A new screen question

#13 Post by Alex »

When you "call" some label "in new context", you need to "return" to game context.

Code: Select all

label explanation: 
   scene bg dict
   ## Long, long explanation
   
   return 
If you need a button, it could be like

Code: Select all

label explanation: 
   scene bg dict
   ## Long, long explanation
   
   $ ui.textbutton ("Return", clicked=ui.returns("True") #place the button on the screen (add xpos, ypos, xalign etc. to change its position; this button actualy do nothing - its just clickable
   $ ui. interact() # game will wait until button clicked
   # when button clicked, we can go farther
   return 

User avatar
azureXtwilight
Megane Procrastinator
Posts: 4118
Joined: Fri Mar 28, 2008 4:54 am
Completed: Fantasia series (ROT and ROTA), Doppleganger: Dawn of The Inverted Soul, a2 (a due), Time Labyrinth
Projects: At Regime's End
Organization: Memento-Mori VNs, Team Sleepyhead
Location: Yogyakarta, Indonesia.
Contact:

Re: A new screen question

#14 Post by azureXtwilight »

That's nice! *writes code*
This thread gave me ideas. . .
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]