Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Hello,
I'm trying to show the output of total affection on a text with this Actor class.
But it gives me an error on line 22.
Anyone mind teaching me how to fix this?
searchwindows wrote: ↑Tue Jan 11, 2022 3:23 am
Hello,
I'm trying to show the output of total affection on a text with this Actor class.
But it gives me an error on line 22.
Anyone mind teaching me how to fix this?
init python:
class Actor:
def __init__(self, character, name, affection):
self.c = character
self.name = name
self.affection = affection
def affection_up(self, amount):
self.affection += amount
def affection_down(self, amount):
self.affection -+ amount
def output(self):
return self.affection
Hai = Actor(Character("Hailey"), "Hailey", 0)
label start:
### $ total_affection = Actor.affection ### removed from script
$ Hai.affection_up(5)
"Your affection score is: [Hai.affection]."
It is showing Hai.affection
I'm not sure what your intention with total_affection is, but that line of code is not doing whatever it is you want it to do.
init python:
class Actor:
def __init__(self, character, name, affection):
self.c = character
self.name = name
self.affection = affection
def affection_up(self, amount):
self.affection += amount
def affection_down(self, amount):
self.affection -+ amount
def output(self):
return self.affection
Hai = Actor(Character("Hailey"), "Hailey", 0)
label start:
### $ total_affection = Actor.affection ### removed from script
$ Hai.affection_up(5)
"Your affection score is: [Hai.affection]."
It is showing Hai.affection
I'm not sure what your intention with total_affection is, but that line of code is not doing whatever it is you want it to do.
[/quote]
Oh I just derped with total_affection.
But for me, [Hal.affection] is returns 0 and not 5 even after add 5 points of affection.
init python:
class Actor:
def __init__(self, character, name, affection):
self.c = character
self.name = name
self.affection = affection
def affection_up(self, amount):
self.affection += amount
def affection_down(self, amount):
self.affection -+ amount
def output(self):
return self.affection
Hai = Actor(Character("Hailey"), "Hailey", 0)
label start:
### $ total_affection = Actor.affection ### removed from script
$ Hai.affection_up(5)
"Your affection score is: [Hai.affection]."
It is showing Hai.affection
I'm not sure what your intention with total_affection is, but that line of code is not doing whatever it is you want it to do.
Oh I just derped with total_affection.
But for me, [Hal.affection] is returns 0 and not 5 even after add 5 points of affection.
[/quote]
Oh it returned the totol after I defined Hai inside init python block instead of outside of it.
But reloading the the script resets the affection score back to 0.
Is there a way to keep it saved but not persistent so it can stil reset when a new game's started?
Oh it returned the totol after I defined Hai inside init python block instead of outside of it.
But reloading the the script resets the affection score back to 0.
Is there a way to keep it saved but not persistent so it can stil reset when a new game's started?
Try
default = Actor(Character("Hailey"), "Hailey", 0)
That would make it a variable and Renpy should save it at it's value at the point of saving.
searchwindows wrote: ↑Wed Jan 12, 2022 4:16 am
But reloading the the script resets the affection score back to 0.
Use default to declare objects which would change during the game. Anything else is not guaranteed to be saved (unless you know exactly what you are doing).
searchwindows wrote: ↑Wed Jan 12, 2022 4:16 am
But reloading the the script resets the affection score back to 0.
Use default to declare objects which would change during the game. Anything else is not guaranteed to be saved (unless you know exactly what you are doing).
Oh it returned the totol after I defined Hai inside init python block instead of outside of it.
But reloading the the script resets the affection score back to 0.
Is there a way to keep it saved but not persistent so it can stil reset when a new game's started?
Try
default = Actor(Character("Hailey"), "Hailey", 0)
That would make it a variable and Renpy should save it at it's value at the point of saving.
is that 'define' gives you a constant and 'default' gives you variable.
A constant is supposed to have one value that is not changed during the game. You technically can change a constant in Renpy, but Renpy will not save the changed value.
A variable on the other hand is intended to have a value that is changed and Renpy will save the latest value.
is that 'define' gives you a constant and 'default' gives you variable.
A constant is supposed to have one value that is not changed during the game. You technically can change a constant in Renpy, but Renpy will not save the changed value.
A variable on the other hand is intended to have a value that is changed and Renpy will save the latest value.
Thanks for the explanation. I understand the difference now.
But default Hailey= Actor(Character("Hailey"), "Hailey", 0) (which I tried as well) gives me invalid syntax error./
searchwindows wrote: ↑Thu Jan 13, 2022 1:49 pm
But default Hailey= Actor(Character("Hailey"), "Hailey", 0) (which I tried as well) gives me invalid syntax error./
Post more of the code. It should work. It is likely you are doing something wrong (like placing default into python block)
searchwindows wrote: ↑Thu Jan 13, 2022 1:49 pm
But default Hailey= Actor(Character("Hailey"), "Hailey", 0) (which I tried as well) gives me invalid syntax error./
Post more of the code. It should work. It is likely you are doing something wrong (like placing default into python block)
That's exactly what I did. i thought i had it out of python block too. My bad