[Feature Request] Setup python block within screen

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
GreatSam
Newbie
Posts: 22
Joined: Wed Aug 28, 2013 10:19 am
Contact:

[Feature Request] Setup python block within screen

#1 Post by GreatSam » Mon Nov 03, 2014 3:34 am

Hi there,

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)
    ...
As the $ lines is computed when the screen is already shown, this isn't a particular good idea to use this code fragment as you all know. Using default on the other hand is something which is computed before the actual screen is shown and works like intended:

Code: Select all

screen foo:
    default text-color = renpy.random.choice(['FFFFFF','000000'])
    text "Foobar" color text-color align(0.5,0.5)
    ...
Unfortunately this very keyword only works with assignments and is therefore pretty limited in its use. Think about something more advanced like this:

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)
    ...
Can't we introduce a whole block of code that is computed as kind of constructor of every screen? Something like:

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)
Of course you can always use stuff like generators to avoid those blocks here, but there may be some advanced code techniques out there which need a whole block to run before a screen gets shown. Think about apps which will first send HTTP requests to some kind of backend before presenting the results within the screen.

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 :)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: [Feature Request] Setup python block within screen

#2 Post by xela » Mon Nov 03, 2014 10:14 am

Could be a bit confusing for some (most?) new users?

There are too many simple, fast and convenient ways of getting this done (some you've already suggested) to turn this into an add-on... that's my view on the issue anyway :)
Like what we're doing? Support us at:
Image

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: [Feature Request] Setup python block within screen

#3 Post by PyTom » Mon Nov 03, 2014 11:03 am

Perhaps just:

Code: Select all

default:
    # python goes here.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

GreatSam
Newbie
Posts: 22
Joined: Wed Aug 28, 2013 10:19 am
Contact:

Re: [Feature Request] Setup python block within screen

#4 Post by GreatSam » Tue Nov 04, 2014 5:26 am

A default block would also be fine - actually, this is what I tried intuitively without looking in the documentation :D

For me this feature would enable a bunch of new possibilities and isn't used by the standard user anyway. For me none of the things to implement my (trivial) example is convenient as it introduces complexity which isn't necessary. Complexity is something we should avoid whenever possible and this in particular helpful to newbies.

If one has to introduce labels or use generators to implement such simple things one could even argue that the current state is especially problematic for newbies. I mean honestly, generators are not the thing you understand when you start with RenPy or python in general and the same applies to labels which are called to call a screen...

Post Reply

Who is online

Users browsing this forum: No registered users