I have a small block of renpy code that is going to be used a lot in my game, and I was hoping to make it into a function so that I can reduce it down to 1 line whenever I need to use it:
Code: Select all
def RelationshipChange(relationship, amt):
show screen affection_bar
with dissolve
$ relationship_currentValue = AnimatedValue(value=(relationship+amt), range=relationship_max, delay=1.5, old_value=relationship)
$ relationship += amt
pause 2.5
hide screen affection_bar
with dissolve
I have already tried the above code, but I am coming back with this error:
Code: Select all
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.
File "game/source/scenes/scene_debug.rpy", line 99: expected statement.
RelationshipChange(temp_value, -25)
^
File "game/source/screens/screen_affectionbar.rpy", line 20: expected statement.
def RelationshipChange(relationship, amt):
^
Ren'Py Version: Ren'Py 6.99.14.3.3347
Sat Jul 07 15:18:16 2018
I got it partially working with this code, but the change to relationship_currentValue stays inside the scope of the function and doesn't affect the outer variable:
Code: Select all
init python:
def RelationshipChange(original, amt):
renpy.show_screen('affection_bar')
renpy.transition(dissolve)
relationship_currentValue = AnimatedValue(value=(original+amt), range=relationship_max, delay=1.5, old_value=original)
original += amt
renpy.pause(2.5)
renpy.hide_screen('affection_bar')
renpy.transition(dissolve)
return original