Thanks enaielei and Ocelot, things are bit more clear now.
"Well, you're on the right track on this one. OOP/Classes are meant for things like this."
That's encouraging, thanks. I have started to learn Python from courses and such on the side, but mainly I learn from actively doing, even if that involves sitting in front of it for hours with only small incremental progress, as I did before I got to the problem I posted, as I no longer understood enough to know what to search for. Which actually isn't really necessary for the project I am working on, as I figured out enough to know how to make it work without using a function, but my take is that even if I don't end up using it I will have learned something and if I manage it then it will be a lot more elegant.
After some more trying around I managed to make it work as I thought it should, thanks to both your help:
Code: Select all
label test:
init python:
class TestFun:
def __init__(self, var1a, var1b):
self.var1a = var1a
self.var1b = var1b
@property
def Output(self):
var1b = self.var1b
var1a = self.var1a
self.var1a = var1a
if var1b == False:
var1a = "unknown"
if var1b == True:
var1a = (self.var1a)
return "var1a: " + str(var1a)
define tfperson = TestFun("VarOneAttA", False)
define j = Character("Jane")
scene white
j "Test line New"
j "[tfperson.Output]"
$ tfperson.var1b = True
j "test line two"
j "[tfperson.Output]"
The main two things were having to make an additional variable to use for the True/False and to use False directly in "define tfperson".
I played around a bit with it already and didn't manage to make it any shorter for now. What I came across that I am not sure of is when trying it this way:
Code: Select all
def __init__(self, var1a, var1b=False):
...
define tfperson = TestFun("VarOneAttA", "VarOneAttB")
There was no error message so, the way I understand it, var1b should be set to False and given that "VarOneAttA" even showed as True when using the other code, I don't know why it's not working just the same.
This is the code I had before, which also works:
Code: Select all
label test2:
init python:
class TestFun:
def __init__(self, var1, show_details = []):
self.var1 = var1
self.show_details = show_details
@property
def Output(self):
var1 = "unknown"
if "var1" in self.show_details:
var1 = self.var1
return "VarOne: " + var1
define tfperson = TestFun("VarOneAtt")
define j = Character("Jane")
scene white
j "Test line New"
j "[tfperson.Output]"
$ tfperson.show_details.append("var1")
j "test line two"
j "[tfperson.Output]"
$ tfperson.show_details.remove("var1")
j "test line three"
j "[tfperson.Output]"
Here it works right away, but in my project the output is, well, I added something like a character screen and either there already, but sure in a subscreen of it which is accessed inside of it, it took several lines to take, as in, line, append, line, no change, line, line, then it changed. That and finding something about Renpy having a problem with saving things lead to going for the other one. Hoping all of this is okay with the whole one question per thing, especially since the OP was already a mess, but since I had that in the OP already as well, is it fine to use a function that works like that in Renpy (even if certain additional things need to be taken care of for it) or is it better to stay away from it?
Well, just in case someone reads this and is inclined to answer, as my main issue is solved and this thread can be declared as such, if that's not something I would have to do.