ijffdrie wrote: ↑Sat Jan 23, 2021 7:19 pm
It's unlikely, but it might be that the style class has a custom comparator function that does something weird when confronted with a comparison with None. Try using
if getattr(style, style_name).xpos is None: (which directly compares the value to None, rather than asking the comparator function to compare it to None).
ijffdrie,
Thank you for the advice.
However, it turned out that the actual problem was that I tried to create named style outside the Ren'Py initialization. The styles were created in the
__init__ method of the
TestClass. The instance of this class was "defined" in the
default statement like this:
Code: Select all
default interface = TestClass(...)
According to doc:
"Ren'Py builds styles on startup, named styles should not be changed outside of a style statement or init block."
The confusion was because of some specificity of the default statement, that allowed to save the changes in the newly created named style in some cases, but didn't save the changes in case of using
Code: Select all
if getattr(style, style_name).xpos == None:
pass
Also due to some specificity of default statement using
style.rebuild() at the end of
__init__ method of the
TestClass helped to save the changes to the created named styles even if the above-mentioned if statement was used.
Conclusion: Due to some specificity of default statement there's a chance that newly created named styles can be modified in the default statement and the changes are saved in the styles. However, this method is not "safe" and can have some hidden problems. This, it is better to follow the advice from the Ren'Py doc and don't create/modify the named styles outside of a style statement or init block.