0 votes

I am currently writing a coding game in which the player needs to write and modify scripts. I would like to have these executed with python, since that reduces the load on me. For these to be executed I have two options:

OS.execute(), or to require it through Gadot native javascript. It does however have the significant downside of not allowing live output of data.

I have also read about GodoPy but as far as I understand i can not have the user call scripts with it. Is there any prebuild solution to execute python scripts in a confined environment from within godot with live console output?

Godot version v3.2.3
in Engine by (12 points)

2 Answers

0 votes

As far as I know, you can't modify or call scripts in-game from your player. Sorry!

by (15 points)
0 votes

OS.execute() is the least complicated of the two as it requires no setup and Just that you have a portable version of Python attached to your game (so as to not trouble your end users with "cant run missing python please download" messages).

func python_call():
    var stdout = []
    var exit = OS.execute("python3", ["script.py"], true, stdout)
    if exit == OK:
        do_stuff_with(stdout)

Note: Its advised to run this function in a separate thread as i doubt you can get an output without blocking which would hang the main thread

by (4,638 points)

The problem with this answer is, that the thread is halted until the program is executed and only then the output can be processed instead of live processing:

https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-execute

If blocking is set to false we will receive no output at all. Another big downside of this is the fact that it would run the scripts on the players computer without restrictions thus allowing them to break out of the game. It would work though.

True this option only simulates the act of "live processing" and that would become noticeable during long processing or scripts that they themselves call OS type functions.

thus allowing them to break out of the game

You don't want your players to exit the game? Are you making a virtual Jumanji?

If your have the technical know how you can build python as a library for Godot using GDnative. I compiled it for Android despite their restrictions so it should be easily achievable.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.