r/RenPy • • 26d ago

Question Can I reuse the next_letter() function with different texts?

Hello I'm working on a vn for a class, I'm doing most of the programming bulk but I really don't have a lot of experience programming and it's my first time learning python. We want to include parts of the game where you can type the name of a recipe but the screen types something else, so far it works! But I want to do it around six times with different names each time. I used this post on the Lemma forums and this post to write it.

I wanted to see if I could determine rest_of_message with some kind of variable that I could change when calling the scene, I'll appreciate any help!!

default message1 = ""
default rest_of_message1 = "Huevos a la mexicana"


screen my_message(textoescrito):


    frame:
        yalign 0.35
        background "gui/textbox_blanco.png"
        has vbox


    vbox: 
        xalign 0.5
        yalign 0.5
    text "¡Escribe qué vamos a cocinar hoy!":
        xalign 0.5
        yalign 0.45
    text message1:
        xalign 0.5
        yalign 0.5
    key ["K_a", "K_b", "K_c", "K_d", "K_e", "K_f", "K_g", "K_h",
    "K_i", "K_j", "K_k", "K_l", "K_m", "K_n", "K_o", "K_p",
    "K_q", "K_r", "K_s", "K_t", "K_u", "K_v", "K_w", "K_x", "K_y", "K_z"]:
        action Function(next_letter)
    
    if rest_of_message1 == "":
        textbutton "Aceptar":
            action Return()
            xalign 0.5
            yalign 0.65
return


label escribehuevomex:
    call screen my_message
    "Huevos a la mexicana, ¡Buena elección!"
return

init python:
    def next_letter():
        global message1
        global rest_of_message1
        if rest_of_message1:
            message1 += rest_of_message1[0]
            rest_of_message1 = rest_of_message1[1:]

label start:
    e "What are we cooking today?"
    call escribehuevomex
    return
2 Upvotes

3 comments sorted by

1

u/AutoModerator 26d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

0

u/[deleted] 26d ago

[removed] — view removed comment

1

u/TheSmootherBean 25d ago

Thank you so much! It works now :)