Turning lists into strings in ren'py variables.

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
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

Turning lists into strings in ren'py variables.

#1 Post by Zeroized » Sat Jul 26, 2014 10:31 pm

Greetings.
I've made a randomizer for the height and the eye color of some NPCs and putting the results in variables, however, the variables aren't being displayed right in the game. I'm assuming that I'm assigning them wrong.

Using the following code:

Code: Select all

$ eyecolorlist = ["red", "blue", "green"]
$ random = renpy.random.randint(0, 2)
$ eyecolor = eyecolorlist[random]

"The character has [eyecolor] eyes"
I'm getting "The character has red eyes", which is the intended result.

However, using this code:

Code: Select all

$ eyecolorlist = ["red", "blue", "green"]
$ random = renpy.random.randint(0, 2)
$ eyecolor = eyecolorlist[random], "eyes"

"The character has [eyecolor]"
I'm getting "The character has ('red', 'eyes')". I think that maybe Ren'py thinks that the second eyecolor variable is a list, while the first is a string. If that's the case, how can turn that list into a string?

Thanks in advance.

User avatar
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Turning lists into strings in ren'py variables.

#2 Post by Asceai » Sat Jul 26, 2014 10:56 pm

The problem is that the comma makes it a tuple.
$ eyecolor = eyecolorlist[random] + " eyes"

User avatar
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

Re: Turning lists into strings in ren'py variables.

#3 Post by Zeroized » Sat Jul 26, 2014 11:03 pm

Oh, I see. I will use + to concatenate the strings then. Thanks for your help.

Post Reply

Who is online

Users browsing this forum: Google [Bot]