User-defined statement:handling arbitrary statement feature?

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
Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

User-defined statement:handling arbitrary statement feature?

#1 Post by Elmiwisa » Sat Aug 24, 2013 9:05 am

(previously a feature request titled: Multi-line user-created statement: feature for next version?)

(previously a Ren'Py coding question titled: About multi-line user created statement)

I am hoping for the ability to create multi-line statement. I am no programmer, but I can't imagine that feature would be too hard to add, even if there is low demand for it, since there is already a single-line version. Of course, we can always use a regular function with a variable number of arguments, but that do not look nice and can't take advantage of the natural nested block structure. :cry:
Additionally, this allow people to share their own multi-line user-created statement in the cookbook, so that if some statement become popular enough, it can be easily added to future generation of Ren'Py. :D
Right now we can override "menu" for all sort of purposes, but that make no sense since menu is meant to make choice, and there are things we can't do with menu anyway since it is after all meant for making a choice and jump. And beside, keep overriding menu for all sort of purposes seems rather haphazard. :oops:


Feature request: allowing user-created statement to receive as its input (in subblock) and handle (which include modification, evaluating expression, and execution) arbitrary Ren'Py/Python statement. :D
Last edited by Elmiwisa on Sun Aug 25, 2013 6:14 am, edited 2 times in total.

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: Multi-line user-created statement: feature for next vers

#2 Post by PyTom » Sat Aug 24, 2013 10:32 am

Actually, Ren'Py already supports multi-line user-created statements.

When registering statements give the register statement the block=True argument. You can then use l.subblock_lexer() to get a lexer for that subblock (sbl), and sbl.advance() to advance between the lines of the block. sbl.advance() returns true if there is a line, and false otherwise.

Code like this parses a block:

Code: Select all

def parse_magic(l)
     l.expect(':')
     l.expect_eol()

     rv = [ ]

     sbl = l.subblock_lexer()
     while sbl.advance()
           rv.append(sbl.integer())
           sbl.expect_eol()
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

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: Multi-line user-created statement: feature for next vers

#3 Post by Elmiwisa » Sat Aug 24, 2013 3:55 pm

OMG this is so awesome, I'm gonna try that now :D :D :D !!! Thanks for pointing that out. :idea:
Is there any chances of getting any detailed documentation on that feature? This page http://www.renpy.org/wiki/renpy/doc/ref ... Statements is the only one I can find that mention user-defined statement, but in light of what you said, it is clearly out of date. Beside, some of the function of lexer is not even listed.
In particular, I am looking at how to:
-Handle an arbitrary Ren'Py statement that is supplied to your user-created statement. For example, if I want to create a statement called random-shuffle that can be used like this:

Code: Select all

random_shuffle:
    e "What is going on?"
    s "Calm down everyone"
    $renpy.show("bg flame")
    "I can't see anything in this commotion."
    "Someone bumped into me."
    menu:
        "Wait and see":
            $choice="wait"
        "Run and scream":
            $choice="run"
And random-shuffle is supposed to run all statement once each, but in a random order. It also need to specifically shuffle the menu choice too. So it would need to run all sort of arbitrary statement, such as the above, other Ren'Py or python statement, and other defined function. We can obtain the lexer for each of these statement as you shown above, but is there anyway to:
(a) modify a lexer for an arbitrary menu?
(b) run an arbitrary statement given its lexer?

-Multiple layer of subblock. So for example defining a statswindow statement that can be used like this:

Code: Select all

statswindow:
    Brian:
        Friendship
        Trust:
            Safety
            Fidelity
        Romance
    Aya:
        Friendship
Basically, this is supposed to show a stats screen that initially show only Brian and Aya, but clicking on Brian expand the screen to show Friendship, Trust and Romance, and clicking on Trust expand the screen to show Safety and Fidelity. So how can I handle arbitrary deep layer of subblock? Is it even possible?

Thanks for your help. :D Oh and since this is not a feature request anymore, you can move it to the other subforum too. I am going to change the title of the thread.

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: About multi-line user-created statement

#4 Post by PyTom » Sat Aug 24, 2013 10:42 pm

User-defined statements can't take Ren'Py code, sorry - that's complex enough I don't want to deal with it.

Additional layers of subblock are possible by calling subblock_lexer on a subblock lexer - pretty much arbitrary complexity can be had that way.
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

Elmiwisa
Veteran
Posts: 476
Joined: Sun Jul 21, 2013 8:08 am
Contact:

Re: About multi-line user-created statement

#5 Post by Elmiwisa » Sun Aug 25, 2013 6:08 am

Oh thanks for the answer. Too bad there is no way to handle arbitrary Ren'Py statement then (and I assume that also means no arbitrary Python code as well?). Well, then this is back to be a feature request! :D When you have time, would you be able to add in the capability to handle arbitrary Ren'Py/Python statement? :idea:

Post Reply

Who is online

Users browsing this forum: No registered users