[Solved]Inserting a variable into a variable

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
GMHLee
Newbie
Posts: 16
Joined: Thu Aug 25, 2022 7:00 am
Contact:

[Solved]Inserting a variable into a variable

#1 Post by GMHLee » Sun Sep 04, 2022 10:49 am

Hi all,

Sorry, couldn't think of the correct terminology but anyways, following in from a previous thread where i wanted to streamline my code, I have this for the moment:

Code: Select all

screen ava_card_text(x1,y1,x2,y2,y3,y4,y5,y6):
    text "Affection:  " style "ultd":
        xanchor 1.0
        xpos x1
        ypos y1
    text "[ava_stats.affection]" style "ultd":
        xanchor 0
        xpos x2
        ypos y1
        ...repeat
Now as i have more than one char I would have to do this multiple times, but given that the only thing that changes between characters for this code is the name and positions I could just do this once but have the name be passed in as a variable like below example (won't work of course):

Code: Select all

screen card_text(x1,y1,x2,y2,y3,y4,y5,y6,char_name):
    text "affection:  " style "ultd":
        xanchor 1.0
        xpos x1
        ypos y1
    text "["+char_name+"_stats.affection]" style "ultd":
        xanchor 0
        xpos x2
        ypos y1
        ...repeat
Any help appreciated for what the correct syntax would be to get this working, thanks.
Last edited by GMHLee on Sun Sep 04, 2022 11:39 am, edited 1 time in total.

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Inserting a variable into a variable

#2 Post by enaielei » Sun Sep 04, 2022 10:58 am

Code: Select all

text "[char_name.affection]" style "ultd"

Code: Select all

use screen card_text(..., ava_stats)

GMHLee
Newbie
Posts: 16
Joined: Thu Aug 25, 2022 7:00 am
Contact:

Re: Inserting a variable into a variable

#3 Post by GMHLee » Sun Sep 04, 2022 11:39 am

Well, that should have been an obvious spot XD
Much appreciated.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]