RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

A place to discuss things that aren't specific to any one creator or game.
Forum rules
Ren'Py specific questions should be posted in the Ren'Py Questions and Annoucements forum, not here.
Post Reply
Message
Author
iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#1 Post by iichan_lolbot »

My game starts in different ways depending on env vars.
So, some files starts with smth like:

Code: Select all

init 10 python:
    if  config_session:
        return
    #lots of resourse initialization here
It works in Ren'Py 6.10.2e and older, but broken in RenPy 6.11.0.
I guess, it is caused by Python update.

I do not want to add LOTS of spaces in ALL my init-sections to create smth like:

Code: Select all

init 10 python:
    if  not config_session:
        #lots of resourse initialization here
Is there another way to replace 'return' with smth?
Last edited by iichan_lolbot on Sun Aug 29, 2010 4:56 pm, edited 1 time in total.

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: RenPy 6.11.0: 'return' outside function

#2 Post by LordShiranai »

It seems like you may want to do what you need within a Python function.

Code: Select all

init python:
    
    def do_stuff():
        if config_session:
            return
        else:
            # Do Stuff

    do_stuff()
At least in Python 2.6, it seems that returns outside of a function are considered to be a syntax error.
Don't Blame Me. I Voted for Vermin Supreme.

Viruzzz
Newbie
Posts: 2
Joined: Tue Jan 12, 2010 6:04 pm
Organization: Moonworks
Tumblr: viruzzz-kun
Github: viruzzz-kun
Soundcloud: viruzzz-kun
Location: Saint Petersburg, Russia
Contact:

Re: RenPy 6.11.0: 'return' outside function

#3 Post by Viruzzz »

Still, there is inevitability to indent a vast amount of code...

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: RenPy 6.11.0: 'return' outside function

#4 Post by LordShiranai »

Viruzzz wrote:Still, there is inevitability to indent a vast amount of code...
Well, this is Python, after all.
Don't Blame Me. I Voted for Vermin Supreme.

Viruzzz
Newbie
Posts: 2
Joined: Tue Jan 12, 2010 6:04 pm
Organization: Moonworks
Tumblr: viruzzz-kun
Github: viruzzz-kun
Soundcloud: viruzzz-kun
Location: Saint Petersburg, Russia
Contact:

Re: RenPy 6.11.0: 'return' outside function

#5 Post by Viruzzz »

Well, I've just "solved" the problem with indentation writing the python script... iichan_lolbot, please, contact me...

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#6 Post by Glazed Donuts »

Is that a Python thing or something? I can't believe I get syntax errors for not indenting! Is there a program or something that anyone recommends that will do the appropriate indentations for Python to be happy?

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#7 Post by LordShiranai »

Yes, Python is very "indentation" dependent.

If find that the JEdit setup included with Ren'Py does as good a job as you're going to get with the indentation.
Don't Blame Me. I Voted for Vermin Supreme.

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#8 Post by Glazed Donuts »

I've been using Jedit, but sometimes it will automatically indent too much or too little (especially if I delete lines of code), and I have to figure out how much to get the indents right x_x is there a way to make it so that it will automatically indent the right amount of spaces no matter what? can this be configured in Jedit somehow?

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#9 Post by LordShiranai »

Glazed Donuts wrote:I've been using Jedit, but sometimes it will automatically indent too much or too little (especially if I delete lines of code), and I have to figure out how much to get the indents right x_x is there a way to make it so that it will automatically indent the right amount of spaces no matter what? can this be configured in Jedit somehow?
Unfortunately, no. There are some cases where the editor really can't figure out what your actual intent with the code is.

Compare these pieces of Python code:

Code: Select all

if x == 1:
    print "x is 1"
x = 0

Code: Select all

if x == 1:
    print "x is 1"
    x = 0
Both of these are valid Python syntax. However, the indentation is important as the x = 0 assignment will always happen in the first snippet, but will only happen in the second snippet if x was previously 1. The editor is not going to be able to figure out what you really want.
Don't Blame Me. I Voted for Vermin Supreme.

Sin
Veteran
Posts: 298
Joined: Thu Oct 18, 2007 3:43 am
Contact:

Re: RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#10 Post by Sin »

In the programming world this is called a gotcha.

It's the biggest, most commonly occurring gotcha that I know of. Why people think it's a good idea (compared to other languages) is beyond me.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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: RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#11 Post by PyTom »

Why people think it's a good idea (compared to other languages) is beyond me.
It's because it prevents other gotchas, and generally improves programmer productivity.

One of the things we teach in the first-level programming is how to indent code. That's because it's hard to read (and reason about) the structure of code without being able to see the blocks visually, through indentation. Since indentation is such a big visual clue, often when reading code that is mis-indented, one can have problems understanding what it does.

Code: Select all

int i = 0;
for (i = 0; i < 10; i++); 
{
    printf("%d\n", i);
}
I'd argue the mistake in the above code
the extraneous semi-colon
is moderately hard to spot - especially if this is a more complicated bit of code. By enforcing the equivalence of indentation and block structure, you make the code easier to understand.

The second reason behind the choice is that it allows one to fit more lines on the screen at once, by not spending 1-2 lines per block on additional punctuation. Since having to scroll up and down makes you a little less productive, reducing scrolling should allow for an increase in productivity.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: RenPy 6.11.0: 'return' outside function [KIND OF FIXED]

#12 Post by Glazed Donuts »

Oh, I still indent my code the old fashioned way. It's just that sometimes, the program gets so fickle about an indentation that's off by an inch and I get some crazy error for it @_@

Post Reply

Who is online

Users browsing this forum: No registered users