According to Tom, it's not possible to double interpolate using str.format(), which makes sense after reading the Python documentation on the subject. However, what I've been practicing is simplifying my code, cutting back on needles disposable variables cluttering the namespace. Currently, I'm looking for a way to display the current time of day in a dialogue. This was the failure: "It's [game.day_times[game.current_time]]."
My object uses a list for the times of day: ["Morning", "Noon", "Afternoon", "Evening", "Night"] and a int for the current time of day (index in list). I'm 100% self taught as a programmer, so there are practices I have not learned, but I'm hoping over time I will develop into a proficient coder. My quest is, what is the most efficient way to resolve this without making a "cast away" variable in the global.
Accessing 2 Object Variables in a Single Interpolation
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.
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.
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Accessing 2 Object Variables in a Single Interpolation
It seems like these variables are part of a class, is that true? How is the class defined?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Re: Accessing 2 Object Variables in a Single Interpolation
It is a class, and this is the simplified version:
Code: Select all
init -4 python:
class Game(object):
def __init__(self):
self.day_times = ["Morning", "Noon", "Afternoon", "Evening", "Night"]
self.current_time = 0
#### In the script.rpy:
default game = Game()
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Accessing 2 Object Variables in a Single Interpolation
You could use properties.
So this is a little script I made, check it out:
So this is a little script I made, check it out:
Code: Select all
init python:
class Game(object):
def __init__(self):
self._day_times = ["Morning", "Noon", "Afternoon", "Evening", "Night"]
self._current_time = 0
@property
def current_time(self): #getter
return self._day_times[self._current_time]
def advance(self):
self._current_time += 1
if self._current_time == 5:
self._current_time = 0
default game = Game()
# The game starts here.
label start:
"Hello! It is [game.current_time]"
"Advancing the game."
$game.advance()
"Now it is [game.current_time]"
"Advancing the game."
$game.advance()
"It is now [game.current_time]"
"Advancing the game"
$game.advance()
"Now it is [game.current_time]"
"Advancing the game."
$game.advance()
"Right now it is [game.current_time]"
"Advancing the game, this should flip it over back to morning."
$game.advance()
"Wow! It is [game.current_time]"
"Let's set the time to a Night specifically."
$game._current_time = 4
"What time is it? It is [game.current_time]"
"Okay, test over."
return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Accessing 2 Object Variables in a Single Interpolation
No worries. Using properties enables you to avoid a bunch of shenanigans.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Who is online
Users browsing this forum: Google [Bot]