Need help with Python in Renpy Label

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
SiddyJUK
Newbie
Posts: 3
Joined: Mon Apr 11, 2022 4:25 am
Contact:

Need help with Python in Renpy Label

#1 Post by SiddyJUK »

Hi all,

I am writting two labels that Ideally I will use several times during the game with different characters. During part of my game the player will have photoshoots with models and then edit the photos in Photoshop. Seeing as the basic layout of the sections would be the same I would like one function that would be able to read from files to load in not only the script for the interactions (and if I can work out how to do it Menu's) but the images that will be displayed.

I am working on the script part first and failing at the first hurdle. I have written a small pure python script as below and this works fine. However when run inside Renpy (Inside a crappy test script) it cannot open the text file:

Code: Select all

label start:
   "Welcome to be crappy test game."
   init python: 
    #images\Models\Amy\Scripts Location of text files. 
    file = open ("images/Models/Amy/txt/sh001.txt")
    content = file.readlines()
    renpy.say (Amy, content[0])
    renpy.say (POV, content[1])
I had the script.py file in my game subfolder and running it it works fine (with print instead of renpy.say)

Should this be possible or am I trying to do something that well cannot be done?

Cheers

User avatar
KuroOneHalf
Regular
Posts: 129
Joined: Fri Apr 25, 2014 6:18 pm
Completed: Cuttlebone
Projects: Somewhere In The Shade
Deviantart: KuroOneHalf
itch: kuroonehalf
Contact:

Re: Need help with Python in Renpy Label

#2 Post by KuroOneHalf »

I'm not certain what you're trying to achieve. Like, why do you want to read plain text files? Why not just put that script in labels?

For this case of having a scene that you want to come up multiple times, you can just put it in its own label. And then to decide which kind of photoshoot variant you should play, you could use a series of if statements.

Code: Select all

label photoshoot(model):
   if model == "Eileen": # have the specific eileen interactions here.
      "Hi Eileen. Please, make yourself comfortable."
   elif model == "Snake":
      "Hi Snake. Looking dashing today."
   #etc. I think you get the idea.

label start:
    # when it comes time to do the photoshoot with, say, Eileen, you do
    call photoshoot("Eileen")

SiddyJUK
Newbie
Posts: 3
Joined: Mon Apr 11, 2022 4:25 am
Contact:

Re: Need help with Python in Renpy Label

#3 Post by SiddyJUK »

Hi,

Thanks for this, and yes I can do it that way. However it would make adding new Models in a little more difficult. What I was looking for was a way of making updates a little easier.

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

Re: Need help with Python in Renpy Label

#4 Post by m_from_space »

I didn't test this, but I assume the problem is that you write "init python:" instead of just "python:"

"init python" tells renpy to initialize this line during startup of the game. Of course if you want to open a file when you start the game, just use init python, but put it outside of the label.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Need help with Python in Renpy Label

#5 Post by zmook »

I feel sure you're making your life harder by not letting ren'py help you with managing your dialog, but if you really insist on doing something like this, you can just call renpy ADVCharacters objects as functions, and they will say the dialog. ie, assuming Amy and POV are ADVCharacters, you can do this:

Code: Select all

    Amy(content[0])
    POV(content[1])
Though seriously, that's a terrible idea, don't do it.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: Bing [Bot]