How to remove the repeating code in a nice way?
By understanding how Ren'Py works ; what is only possible if you starts by reading the documentation.
"
You must be registered to see the links
"
"
You must be registered to see the links
"
Therefore, "livia_neutral" and "livia_happy" should be named "livia neutral" and "livia happy".
That way,
show livia happy
would automatically hide "livia neutral", replacing it by "livia happy".
"
You must be registered to see the links
"
"
You must be registered to see the links
"
Therefore the
window hide
and
window show
will follow soon or later are not needed.
Python:
label start:
scene default_background
with fade
show livia_neutral
$ loop = True
while loop:
menu:
"What should I do?"
"Make her happy":
hide livia_neutral
show livia_happy
window hide
pause
hide livia_happy
"Make her angry":
hide livia_neutral
show livia_angry
window hide
pause
hide livia_angry
"Exit":
$ loop = False
show livia_neutral
return
I wanted to create another label with the repeating code in it, and call it with the image livia_x, but that didn't work for some reason.
"
You must be registered to see the links
"
The last sentence is a question of convenience.
hide
also accept the "expression" keyword, therefore the tag is optional when you are in full control of the flow.
But if, by example, the second image should be hidden, and hidden from another part of the code, the tag become mandatory. It would be the only way to know what image to address.
[Note: This follow the corrected code, not the original one]
Python:
label whatever( mood ):
show expression "livia {}".format( mood )
pause
show livia neutral
return
label start:
scene default_background
with fade
show livia neutral
$ loop = True
while loop:
menu:
"What should I do?"
"Make her happy":
call whatever ( "happy" )
"Make her angry":
call whatever ( "angry" )
"Exit":
$ loop = False
"END"