sometimes I would like to have some code to run before a screen is shown. Consider the following example:
Code: Select all
screen foo:
$ text-color = renpy.random.choice(['FFFFFF','000000'])
text "Foobar" color text-color align(0.5,0.5)
...
Code: Select all
screen foo:
default text-color = renpy.random.choice(['FFFFFF','000000'])
text "Foobar" color text-color align(0.5,0.5)
...
Code: Select all
screen foo:
default colors = ['FFFFFF','000000','C0C0C0']
default text-color1 = renpy.random.choice(colors)
default text-color2 = renpy.random.choice([ c for c in colors if c != text-color1 ]) # take another color which is NOT text-color1
text "Foobar" color text-color1 align(0.5,0.5)
text "Barfoo" color text-color2 align(0.2,0.2)
...
Code: Select all
screen foo:
python <constructor/init-screen/enter/whatever>:
colors = ['FFFFFF','000000','C0C0C0']
text-color1 = renpy.random.choice(colors)
colors.remove(text-color1)
text-color2 = renpy.random.choice(colors)
text "Foobar" color text-color1 align(0.5,0.5)
text "Barfoo" color text-color2 align(0.2,0.2)
To me it looks like the fundamental idea of this is already implemented by the default keyword, but is limited to assignments (which can be a pain to when it comes to advanced techniques). I know that you can always work around this problem by calling a label which than calls the screen after the python expression are evaluated, but for me this isn't a nice thing to do. If you're code belongs to a screen it should be in the screen and not require additional constructs like labels to run.
You could argue the same when it comes to a destructor as those may also be helpful (e.g. for closing an HTTP connection if the screen is closed).
So that's it basically. Tell me your view on this issue
