Storing multiple data in one 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
ketskari
Veteran
Posts: 296
Joined: Tue Dec 21, 2010 6:22 pm
Completed: Asher, Sunrise, Tell a Demon
Projects: Asher Remake, TEoA
Organization: Sun Labyrinth
Tumblr: sunlabyrinth
Deviantart: sunlabyrinth
itch: sunlabyrinth
Contact:

Storing multiple data in one variable? [SOLVED]

#1 Post by ketskari »

Basically, I want to be able to change the string, like so:

Code: Select all

$ fruit = "apple"
Where "apple" also has a value. 1 might indicate it's edible, 2 might indicate it's overripe and 3 might indicate it's rotten, for instance.

So, a bunch of fruit might have data like this:

Fruit
"apple" 1
"orange" 3
"pear" 1
cantaloupe 2

How do I do this? Or what is this called so I can look it up?

Thanks.
Last edited by ketskari on Sat Jul 23, 2016 8:14 pm, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Storing multiple information in one variable? like a tab

#2 Post by Alex »

You can use a dictionary to store information about each fruit and a list to store all the fruits, like

Code: Select all

inventory_list = [ {"name":"apple", "condition":1}, {"name":"orange", "condition":3} ]
https://docs.python.org/3/tutorial/datastructures.html

User avatar
ketskari
Veteran
Posts: 296
Joined: Tue Dec 21, 2010 6:22 pm
Completed: Asher, Sunrise, Tell a Demon
Projects: Asher Remake, TEoA
Organization: Sun Labyrinth
Tumblr: sunlabyrinth
Deviantart: sunlabyrinth
itch: sunlabyrinth
Contact:

Re: Storing multiple information in one variable? like a tab

#3 Post by ketskari »

Thanks so much!

Post Reply

Who is online

Users browsing this forum: Google [Bot]