[Advice Needed] In-depth explanation for "Use" and "id"

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
AceQueenKimu24
Newbie
Posts: 19
Joined: Mon May 08, 2017 5:17 am
Projects: Blooming Romance | Marionette
Deviantart: 24WildHeart
itch: 24_wildheart
Contact:

[Advice Needed] In-depth explanation for "Use" and "id"

#1 Post by AceQueenKimu24 »

Hi there! I've been reading up a lot on the documentation, searching in reddit and lsf, and as well as checking through other codes for examples, but I don't think I can really grasp the concept of how to use, well... use and id. Does anyone perhaps know a thread or tutorial that can explain these tags more in depth?

For context, I'm trying to completely overhaul the navigation and game menu of my game, and I'm hesitant since it might cause the game to bug out when I'm not completely informed,,,
Image

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: [Advice Needed] In-depth explanation for "Use" and "id"

#2 Post by hell_oh_world »

- `use` (as based on this: https://www.renpy.org/dev-doc/html/screens.html#use) is a screen statement that enables you to use a predefined screen that you made inside a screen. you can use `use` to recycle screens as well as creating templates for your displayables around the screen.
to use this, create first a screen of your choice. then in your actual screen use `use <screen_name>` to put that screen inside the screen.

Code: Select all

screen red_square():
  frame:
    background "#f00"
    xysize (100, 100)

screen actual_screen():
  use red_square

be noted that this is a screen we're talking to we can pass stuff around this and use this with `use` statement as well.

Code: Select all

screen red_square(**properties):
  frame:
    properties properties # the properties is documented at the link I sent. it just takes the passed property and apply it into the displayable

screen actual_screen():
  use red_square(
    background="#f00",
    xysize=(50, 50))
you can also use `transclude` which makes using the `use` statement more awesome. and its documented as well in the docs.

Code: Select all

screen red_square(**properties):
  frame:
    properties properties # the properties is documented at the link I sent. it just takes the passed property and apply it into the displayable
    
    transclude # any child that you'll pass when using the use statement in this screen will be placed inside this frame.

screen actual_screen():
  use red_square(
    background="#f00",
    xysize=(50, 50)): # observe the colon, we can now use the red_square as a container
    text "Hello World" # imagine this text replacing the `transclude` in the definition of red_square
- `id` is simply just a property that any displayable can take (buttons, frames, windows, texts, etc.). It uses a string wherein this string can be later referenced using the `renpy.get_widget() and renpy.get_widget_properties()` functions (https://www.renpy.org/doc/html/screen_p ... get_widget). So in other sense, `id` only makes sense if you're planning to use these functions.

User avatar
AceQueenKimu24
Newbie
Posts: 19
Joined: Mon May 08, 2017 5:17 am
Projects: Blooming Romance | Marionette
Deviantart: 24WildHeart
itch: 24_wildheart
Contact:

Re: [Advice Needed] In-depth explanation for "Use" and "id"

#3 Post by AceQueenKimu24 »

hell_oh_world wrote: Wed Dec 23, 2020 9:36 pm - `use` (as based on this: https://www.renpy.org/dev-doc/html/screens.html#use) is a screen statement that enables you to use a predefined screen that you made inside a screen. you can use `use` to recycle screens as well as creating templates for your displayables around the screen.
to use this, create first a screen of your choice. then in your actual screen use `use <screen_name>` to put that screen inside the screen.

Code: Select all

screen red_square():
  frame:
    background "#f00"
    xysize (100, 100)

screen actual_screen():
  use red_square

be noted that this is a screen we're talking to we can pass stuff around this and use this with `use` statement as well.

Code: Select all

screen red_square(**properties):
  frame:
    properties properties # the properties is documented at the link I sent. it just takes the passed property and apply it into the displayable

screen actual_screen():
  use red_square(
    background="#f00",
    xysize=(50, 50))
you can also use `transclude` which makes using the `use` statement more awesome. and its documented as well in the docs.

Code: Select all

screen red_square(**properties):
  frame:
    properties properties # the properties is documented at the link I sent. it just takes the passed property and apply it into the displayable
    
    transclude # any child that you'll pass when using the use statement in this screen will be placed inside this frame.

screen actual_screen():
  use red_square(
    background="#f00",
    xysize=(50, 50)): # observe the colon, we can now use the red_square as a container
    text "Hello World" # imagine this text replacing the `transclude` in the definition of red_square
- `id` is simply just a property that any displayable can take (buttons, frames, windows, texts, etc.). It uses a string wherein this string can be later referenced using the `renpy.get_widget() and renpy.get_widget_properties()` functions (https://www.renpy.org/doc/html/screen_p ... get_widget). So in other sense, `id` only makes sense if you're planning to use these functions.
That's a little more understandable, thank you! Though if you don't mind me asking, I'd sometimes see use take a parameter and contain a block like this:

Code: Select all

use game_menu(_("History"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0):
	##insert code
And I'm rather confused as to which screen would be in which and which properties would be applied where.
Image

Shie
Regular
Posts: 41
Joined: Sun Apr 14, 2019 4:12 am
itch: shie
Discord: shie_3769
Contact:

Re: [Advice Needed] In-depth explanation for "Use" and "id"

#4 Post by Shie »

Code: Select all

use game_menu(_("History"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0):
	##insert code
In screen game_menu is such construction:

Code: Select all

frame:
    # here somewhere is use navigation
    text dont_remember_but_it_where_"History_goes"
    if scroll == "vpgrid":
        vpgrid:
            transclude
    elif scroll == "vievport":
        viewport:
            transclude
    else:
        transcude
This code set which branch is used, text above(history, preferences,about,etc) and if vpgrid or viewport what part of history/etc shown first
In this case screen history uses game_menu and is inserted in vpgrid, vpgrid scarts at last say statement, text at up left is "History"

User avatar
AceQueenKimu24
Newbie
Posts: 19
Joined: Mon May 08, 2017 5:17 am
Projects: Blooming Romance | Marionette
Deviantart: 24WildHeart
itch: 24_wildheart
Contact:

Re: [Advice Needed] In-depth explanation for "Use" and "id"

#5 Post by AceQueenKimu24 »

OH, so it literally means which configuration to use then? If so, I understand then, thank you for your help! ^^
Image

Post Reply

Who is online

Users browsing this forum: apocolocyntose