I've been using a method for selecting random lines within a dialog, and it mostly works great, but I hit a snag when trying to use a variable within that dialog, in that basically it does not use the variable and instead just says the variable name. Here's what I'm working with in simple form:
Code: Select all
$ Weapon = "sword"
$ Enemy = "slime"
$ Line = renpy.random.choice(["You swing your [Weapon].",
"You leap over the [Enemy]'s attack and bring your [Weapon] down on its head.",
"You dodge to the side and then stab the enemy."])
"[Line]"
Now I use it in a more complex fashion later, but not in a way that should change anything. Anyways, the intended behavior is obviously that if option 2 gets chosen, when it gets to "[Line]" it will say "You leap over the
slime's attack and bring your
sword down on its head.", instead it says "You leap over the [Enemy]'s attack and bring your [Weapon] down on its head." I'm guessing it's because when I reference a variable in a string, that is then added into a variable, it has trouble referencing those variables? Like maybe it doesn't parse what the actual variable is when I assign the Line, but rather when it's displayed or something? Is there some simple workaround for this? If not I can just rewrite the portions that don't work, but I could make some more interesting narrative if I can make this work.