Local (nested) labels proposal

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
User avatar
caryoscelus
Newbie
Posts: 19
Joined: Wed Sep 10, 2014 4:46 pm
IRC Nick: caryoscelus
Github: caryoscelus
Location: Earth
Contact:

Local (nested) labels proposal

#1 Post by caryoscelus » Wed Apr 13, 2016 9:52 am

When the script is heavy-choice, amount of labels can soon get unmanageable. I think the usual way to avoid name collisions is to use something like "chapter1_episode1_choice1", but it is ugly, verbose and still doesn't guarantee avoidance of collisions, especially when using third-party code.

To resolve this problem i propose introducing 'local' labels, which can have identical names inside different 'global' labels. Here's how it works:

Code: Select all

label global_label:             # normal label, nothing changed for its behaviour
  "..."
label .a:                       # local label fully identified as global_label.a
  "..."
  jump .a                       # local jump, resolved to global_label.a

label another_global_label:
  "..."
label .a:                       # another_global_label.a
  jump global_label.a
Syntax-wise, it's fully backwards compatible since currently label names cannot contain dot and thus all existing labels are considered global with this change.

It is also possible to expand this idea to have no nesting limit (i.e. making possible to have label a.b.c.d and jump to it inside a.b.c scope by simply "jump ...d")

I also found out that it is currently possible to 'nest' labels using indentation, but it doesn't protect from name collisions. It is possible to implement the same mechanism with such nested labels, but since it uses old syntax, it can cause problems with existing code. Also, it is more visual which can sometimes be good, but can also be bad when you prefer all statements to be on same indentation level.

I already have half-working implementation, but i thought to post proposal here for discussion first.

What are your thoughts on this?
PyTom, would you accept such feature?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Local (nested) labels proposal

#2 Post by nyaatrap » Wed Apr 13, 2016 11:52 am

I use jump/call expression str+"_"+str, so name ( I think they're stores as strings not variables, am I correct?) confliction is not problem for me.
But I want to know current mechanics of how label indentation work.
I tried nested label, and it actually works with no error. I thought it throws an error (and not documented) but how it's working?

User avatar
caryoscelus
Newbie
Posts: 19
Joined: Wed Sep 10, 2014 4:46 pm
IRC Nick: caryoscelus
Github: caryoscelus
Location: Earth
Contact:

Re: Local (nested) labels proposal

#3 Post by caryoscelus » Wed Apr 13, 2016 1:18 pm

nyaatrap wrote:I use jump/call expression str+"_"+str, so name ( I think they're stores as strings not variables, am I correct?) confliction is not problem for me.
That of course works when you fully control the code, have good naming scheme and remember all top-level labels, but it's more verbose. And yes, labels are separate from vars.
nyaatrap wrote:But I want to know current mechanics of how label indentation work.
I tried nested label, and it actually works with no error. I thought it throws an error (and not documented) but how it's working?
From what i can tell (i looked up the code), there is no difference in behaviour. It is parsed differently, but since label names are collected recursively (and all Label node does is skip to next statement), they will work as normal labels.

Post Reply

Who is online

Users browsing this forum: No registered users