- Jun 10, 2017
- 11,018
- 16,315
Why so complicated in terms of use ?You can also consider adding code for repetitive actions, for example if you have a point based system that awards points based on an action, that also displays a message to the user - instead of repeating everything each time you can use something like:
And in your script you would just use:Python:init python: def change_stat(stat, amount): if rel_notify: if amount > 0: renpy.notify("Your relationship has increased!") else: renpy.notify("Your relationship has decreased!") stat += amount return stat
POINT_VARIABLE is your specific variable for the points, the 1 can be any number, even a negative to reduce points.Python:$ POINT_VARIABLE = change_stat(POINT_VARIABLE, 1)
There's two easier, and more flexible ways to do this:
In Python:
Python:
init python:
def change_stat(stat, amount=1, notify=True):
# Change the value
setattr( store, stat, getattr( store, stat ) + amount )
if notify:
renpy.notify("Your relationship has {}!".format( "increased" if amount > 0 "decreased" )
label whatever:
# Add 1 and notify ; the most frequent use.
$ change_stat( "myVar" )
# Remove 1 and notify
$ change_stat( "myVar", -1 )
# Add 1 but don't notify
$ change_stat( "myVar", notify=False )
# Add 5 and don't notify
$ change_stat( "myVar", 5, False )
Python:
label change_stat( stat, amount=1, notify=True ):
$ setattr( store, stat, getattr( store, stat ) + amount )
if notify:
$ renpy.notify("Your relationship has {}!".format( "increased" if amount > 0 "decreased" )
return
label whatever:
call change_stat( "myVar" )
It can also works if you use an object to store the points, and then have more precise notifications:
Python:
init python:
def change_stat( who, stat, amount=1, notify=True):
# Change the value
setattr( who, stat, getattr( who, stat ) + amount )
if notify:
# Assuming the object have a /name/ attribute.
renpy.notify("{}'s {} has {}!".format( who.name, stat.title(), "increased" if amount > 0 "decreased" )
label whatever:
$ change_stat( sarah, "love" )
$ change_stat( anna, "lust", -1 )