What is the correct syntax to show dict variables on a menu?

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
Dreigous
Newbie
Posts: 1
Joined: Sat Aug 13, 2022 12:28 am
Contact:

What is the correct syntax to show dict variables on a menu?

#1 Post by Dreigous » Sat Aug 13, 2022 12:29 am

Hey guys. I have a problem that has me stumped, and no matter where I look or what I try I can't seem to solve it hahaha. And so I wanted to know if you guys knew the solution.

Alright, so I have a dictionary. And I want to show one of the variables in the dictionary inside of a menu option. Now, the code I wrote works perfectly if instead of the variable I use a number. But if I try to use a variable, I think it reads it as text, and so it freaks out. So I wanna know what should I write if I want to use a variable.

I'll love you forever if you help me lel.

menu: "Whatever the option is [dict[key][variable]]":

The dictionary goes something like this.


default dict= {
'key':
['lal', 'lel', 'lil'],

User avatar
m_from_space
Veteran
Posts: 302
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: What is the correct syntax to show dict variables on a menu?

#2 Post by m_from_space » Sun Aug 14, 2022 1:27 pm

Interpolating variables and especially dictionaries that have multiple levels can be a challenge. Just do it like this, it's also way easier to adapt if you change your dict later on in the game:

Code: Select all

$ option = dict['key'][variable]
menu:
    "Whatever the option is [option]":

Post Reply

Who is online

Users browsing this forum: Google [Bot]