I wrote a code to create a building when the timer ends. My buildings are a class where I define the time needed to create the building (build_time) and a timeleft for each building.
I know how to write a timer for a specific object like this one:
Code: Select all
init python:
class Building:
def __init__(self, name, img, loc = 0, timeleft = 0, time_build = 0):
self.name = name
self.img = img
self.timeleft = timeleft
self.time_build = time_build # the time needed to build the building
Building.loc = loc #not important for my question
def start_building_timer(self):
self.timeleft = self.time_build
def end_building_timer(self):
global nbr_building
nbr_building += 1
self.timeleft = 0
screen timer_screen:
on "show" action Function(renpy.retain_after_load)
zorder 3
if building01.timeleft>1:
timer 1.0 action SetVariable("building01.timeleft", building01.timeleft-1) repeat True
elif building01.timeleft == 1:
timer 1.0 action Function(building01.end_building_timer)
vbox:
text "building01.time_build: [building01.time_build]"
text "building01.timeleft: [building01.timeleft]"
text "nbr_building: [nbr_building]"
textbutton "create building" action Function(building01.start_building_timer)
define building01 = Building("house", "",0, 0, 15)
define nbr_building = 0
label start:
show screen timer_screen
"You've created a new Ren'Py game."
return
But I love buildings and I want to create 10'000 different buildings
Also, I want to use the same timer code for my 10'000 buildings...
I tried to do that, but it doesn't work because it's not y python class but a renpy screen language. And to be honest, I'm not really sure of what I did...
Code: Select all
if self.timeleft>1:
timer 1.0 action SetVariable("self.timeleft", self.timeleft-1) repeat True
elif self.timeleft == 1:
timer 1.0 action Function(self.end_building_timer)
One more question: does exist a Statement Equivalents in python of the renpy timer ? (perhaps something like renpy.timer() )