Setting variable as another variable (solved)

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
Smaymay
Regular
Posts: 70
Joined: Fri Jul 01, 2016 11:35 am
Completed: Vicboys demo
Tumblr: esmmeh
Deviantart: Smaymay
Location: The Netherlands
Contact:

Setting variable as another variable (solved)

#1 Post by Smaymay »

Hi there, I'm coding the point system at the moment to determine which character the player will end up with. Of course, there are also scenes for the possibility that you end up with a tie. The system works fine at the moment except for one tiny detail.

Code: Select all

if tiedBetweenTwo == True:
        show choiceOverlay
        menu:
            "[tiedBoy1]":
                hide choiceOverlay
                $ boyChoice = "[tiedBoy1]"
                $ renpy.fix_rollback()
                MC "[tiedBoy1]?"
                MC "Of course!"
            "[tiedBoy2]":
                hide choiceOverlay
                $ boyChoice = "[tiedBoy2]"
                $ renpy.fix_rollback()
                MC "[tiedBoy2]?"
                MC "Of course!"
The game will fill in the right name for those tiedBoy variables used in the dialogue. But when I try to use the boyChoice variable...

Code: Select all

MC "[boyChoice], you will be mine!"
This will just print out [boyChoice] instead of the name set to one of the tiedBoy variables.

I was wondering if it's possible at all to set a variable as another variable. But this could be a syntax error on my part after all! Thanks in advance :)
Last edited by Smaymay on Fri Jan 11, 2019 7:47 am, edited 1 time in total.

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Setting variable as another variable

#2 Post by philat »

$ boyChoice = tiedBoy1

User avatar
Smaymay
Regular
Posts: 70
Joined: Fri Jul 01, 2016 11:35 am
Completed: Vicboys demo
Tumblr: esmmeh
Deviantart: Smaymay
Location: The Netherlands
Contact:

Re: Setting variable as another variable

#3 Post by Smaymay »

@philat

Oh damn. It works haha. I feel so dumb. Thanks for the quick reply. Learned something new today ^^

philat
Eileen-Class Veteran
Posts: 1910
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Setting variable as another variable (solved)

#4 Post by philat »

No problem. Interpolation (in whatever form you may come across, .format() or % or []) is only necessarily when you want to put the variable in a STRING. In all other contexts, it's just the variable name.

Post Reply

Who is online

Users browsing this forum: No registered users