Page 1 of 1

Renpy don't get python function if it not in the same rpy

Posted: Sat Nov 19, 2016 4:52 am
by Eliont
Hello and good time of day.
Tryed to migrate to new version and encountered a bug:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 12, in script
    python:
  File "game/script.rpy", line 30, in <module>
    work_actions_desc = load_work_action_descriptions('db/work actions descriptions')
NameError: name 'load_work_action_descriptions' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 12, in script
    python:
  File "D:\Soft\renpy-6.99.11-sdk\renpy\ast.py", line 805, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Soft\renpy-6.99.11-sdk\renpy\python.py", line 1641, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 30, in <module>
    work_actions_desc = load_work_action_descriptions('db/work actions descriptions')
NameError: name 'load_work_action_descriptions' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.99.11.1749
Legends_of_Alkion 1.0
This function is located in lib - functions.rpy.
If i copy her to script.rpy, it works, but this is not acceptable.

Re: Renpy don't get python function if it not in the same rp

Posted: Sat Nov 19, 2016 12:03 pm
by xela
Privet :)

Delete all .rpyc files and try again.

Re: Renpy don't get python function if it not in the same rp

Posted: Sat Nov 19, 2016 12:24 pm
by Eliont
Hi. Did not work. Lol, i tried it in the first place, and tried again just now, problem still exist.

"Force Recompile" also did not help.

Re: Renpy don't get python function if it not in the same rp

Posted: Sat Nov 19, 2016 1:06 pm
by xela
:(

It's not Ren'Py 6.99.11 in off itself... maybe the func is defined twice or was moved at some point. When you deleted .rpyc, did you use windows search to locate all files? This has happened to me a couple of times after major refactoring as code was moved between files.

Re: Renpy don't get python function if it not in the same rp

Posted: Sat Nov 19, 2016 1:21 pm
by Eliont
In 6.11 worked just fine.
Function has one and only place and one and only use.

If i copy her to script.rpy then launch break on next function call - load_content.

Hmm, just noticed, it not next. Functions that defined in lib - common.rpy was loaded succesfully.
Copied lib - functions.rpy content to the end of lib - common.rpy and game launched succesfully.

IDK what the hell it is.

Re: Renpy don't get python function if it not in the same rp

Posted: Sat Nov 19, 2016 1:54 pm
by PyTom
You do have to care about init order here. While functions in a single file are defined from top to bottom, files can be loaded in any order. So you probably want to define functions in an init python block, but call them in an "init 1 python" block, to make sure the functions are defined before being called.

Re: Renpy don't get python function if it not in the same rp

Posted: Sat Nov 19, 2016 11:55 pm
by Eliont
i dont think its about init order...

Code: Select all

# The game starts here.
label start:
    show screen debugTools
    python:    
        work_actions_desc = load_work_action_descriptions('db/work actions descriptions')

Re: Renpy don't get python function if it not in the same rp

Posted: Sun Nov 20, 2016 12:20 am
by PyTom
That should work. What's the error, and what file is the code in?

Re: Renpy don't get python function if it not in the same rp

Posted: Sun Nov 20, 2016 12:38 am
by Eliont
Error code in the first post.

Well, idk what was there, but when i deleted lib-functions.rpy and placed its content in a new file with the same name error gone. May be the file itself been corrupted at filesystem level (but Notepad++ operated with them with no problem).