The first part is to open up a file to write the script from input in the game. That I've managed to do.
The second part is to actually compile and execute. When using the following code, test.py is called up perfectly when run from the command line or directly from the window with a double click:
Code: Select all
filename = "test.py"
with open(filename, "rb") as source_file:
code = compile(source_file.read(), filename, "exec")
exec(code)
Code: Select all
filename = os.path.join(renpy.config.gamedir, "texts\\test.py")
with open(filename, "rb") as source_file:
code = compile(source_file.read(), filename, "exec")
exec(code)
Code: Select all
filename = "test.py"
source_file = renpy.file(filename)
code = compile(source_file.read(), filename, "exec")
exec(code)
Code: Select all
filepath = os.path.join(renpy.config.gamedir, "texts\\test.py")
global_namespace = {
"__file__": filepath,
"__name__": "__main__",
}
with open(filepath, 'rb') as file:
exec(compile(file.read(), filepath, 'exec'), global_namespace)
I'm running Windows 10 with Python installed. What's the catch? Is is a permission thing? A scope thing? I'm trying all options, but I might've missed something...
I really could use some help, since it's for a thesis I'm making on educational games and computer science. Thanks, guys.