Page 1 of 1

Trouble with text variables [Solved]

Posted: Sat May 10, 2014 9:32 pm
by pancito
This should be simple, but I can't find it anywhere. I'm just starting out, and I'm prolly doping something totally stupid, so there's that as well... So frustrated I actually joined the forum. :D

Here's the code, totally generic.

Code: Select all

# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")
$ age1 = 18
$ age2 = "eighteen"
$ age3 = 'eighteen'

# The game starts here.
label start:

    e "You've created a new Ren'Py game."

    e "I'm [age3] years old."

    return
I've tried all three of the variables but all error out. Here's the traceback.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 17, in script
    e "I'm [_age3] years old."
KeyError: u'_age3'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 17, in script
    e "I'm [_age3] years old."
  File "C:\Users\me\Desktop\Games\renpy-6.17.6-sdk\renpy\ast.py", line 558, in execute
    renpy.exports.say(who, what, interact=self.interact)
  File "C:\Users\me\Desktop\Games\renpy-6.17.6-sdk\renpy\exports.py", line 925, in say
    who(what, interact=interact)
  File "C:\Users\me\Desktop\Games\renpy-6.17.6-sdk\renpy\character.py", line 808, in __call__
    what = what_pattern.replace("[what]", sub(what, translate=translate))
  File "C:\Users\me\Desktop\Games\renpy-6.17.6-sdk\renpy\substitutions.py", line 223, in substitute
    s = formatter.vformat(s, (), kwargs)
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 549, in vformat
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 571, in _vformat
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 632, in get_field
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 591, in get_value
KeyError: u'_age3'

Thanks for any help!

Re: Trouble with text variables

Posted: Sat May 10, 2014 9:35 pm
by briannavon
They are in the wrong place. Variables go after label start. :D

Re: Trouble with text variables

Posted: Sat May 10, 2014 9:45 pm
by pancito
See! I told you it was simple. Thanks briannavon! And just for completeness, any one of those three formats will work (either single or double quotes) as long as it is in the right place.