So I've been doing an exploration of bars in order to answer NaNaNaNoo's question about bars as fully as possible. I've been trying to utilize all the Bar Variants in the documentation:
The basic bar screen language doc: http://www.renpy.org/doc/html/screens.html#bar
Using the different BarValues as my value object, especially the AnimatedValue: http://www.renpy.org/doc/html/screen_ac ... tml#values
Making Bars that can adjust a value using ui.adjustment:http://www.renpy.org/doc/html/screen_py ... adjustment
Then I checked to see if I could create a basic BarValue object and have that work: http://www.renpy.org/doc/html/screen_py ... #barvalues
I've got everything working so far. And note, I will post the results of my experimentation when I'm completely finished with it.
But I'm stuck at something. According to the BarValue documentation, I should be able to use periodic to make it animate value changes just like the AnimatedValue. BarValue also can take an adjustment. So, I figured I could create a BarValue that would use an adjustment and that would use animations. This I'm having trouble with. Any help?
So here is my version of using BarValue without Animation that does work:
Code: Select all
screen barvaluebar():
vbox:
xmaximum 300
bar value bhvaluebar
text "HP: [hp]/[max_hp]"
init -1 python:
def updateHP(variable):
global hp
hp = variable
renpy.restart_interaction()
class HPValue(BarValue):
def __init__(self, value=0.0, range=1.0):
self.value = value
self.range = range
def get_adjustment(self):
return ui.adjustment(value=hp, range=max_hp, changed=updateHP)
# The game starts here.
label start:
$max_hp = 100
$hp = 50
$bhvaluebar = HPValue(value=hp, range=max_hp)
scene black
"This is going to be an exploration of Bars."
show screen barvaluebar()
"Now we do an adjustable value bar using BarValue."
"Try it out."
$hp += 25
"Adding 25."
$hp -= 25
"Subtracting 25."
hide screen barvaluebar
returnCode: Select all
screen barvaluebar2():
vbox:
xmaximum 300
bar value bhvaluebar2
text "HP: [hp]/[max_hp]"
init -1 python:
def updateHP(variable):
global hp
hp = variable
renpy.restart_interaction()
class HPValue2(BarValue):
def __init__(self, value=0.0, range=1.0, delay=1.0, old_value=None):
if old_value == None:
old_value = value
self.value = value
self.range = range
self.delay = delay
self.old_value = old_value
self.start_time = None
self.adjustment = None
def get_adjustment(self):
self.adjustment = ui.adjustment(value=hp, range=max_hp, changed=updateHP)
return self.adjustment
def periodic(self, st):
if self.start_time is None:
self.start_time = st
if self.value == self.old_value:
return
fraction = (st - self.start_time) / self.delay
fraction = min(1.0, fraction)
value = self.old_value + fraction * (self.value - self.old_value)
self.adjustment.updateHP(value)
if fraction != 1.0:
return 0
def replaces(self, other):
if not isinstance(other, AnimatedValue):
return
if self.value == other.value:
self.start_time = other.start_time
self.old_value = other.old_value
else:
self.old_value = other.value
self.start_time = None
# The game starts here.
label start:
$max_hp = 100
$hp = 50
$hpadjust1 = ui.adjustment(value=hp, range=max_hp, changed=updateHP)
$bhvaluebar2 = HPValue2(value=hp, range=max_hp, delay=2.0)
scene black
"This is going to be an exploration of Bars."
show screen barvaluebar2()
"Now we do an adjustable value bar using BarValue with animation."
"Try it out."
$hp += 25
"Adding 25."
$hp -= 25
"Subtracting 25."
hide screen barvaluebar2
returnHelp will be included in my exploration that I will eventually publish in the cookbook!

