Communicate GDscript with Python

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JayJay99

I know that this question was already asked on this forum, but I couldn’t find any proper answer to it, they just link to the godot-python repository (GitHub - touilleMan/godot-python: Python support for Godot 🐍🐍🐍) wich dosen’t seen to have a documentation, i just wanna know how to do that in code, how to send and get information from one script to another, I am developing a game in godot and a friend of mine is creating an AI in python for the game.

Also, when I went to the Godot python repository, it gave me a 404 error - the author probably removed it or something.

Snail0259 | 2021-07-09 20:56

:bust_in_silhouette: Reply From: Snail0259

If you don’t need to have it update very quickly, you can write to a file in gdscript (eg. input.csv), send it to python, use that data as inputs (using keras/tensorflow or something), then write the outputs to a file in python, and read them in gdscript. You do always need the python script to be running in the background, however.

:bust_in_silhouette: Reply From: Wakatta

Since you’ve got two agents and you want them to communicate.
Go with a TCP or UDP server and client respectively.

Simply send the instructions in packets (encrypted of course)
Then open up a communication between the python AI and Godot game through the localhost


If you wanted a more direct approach then you could technically operate python through Godot’s OS.execute() function or python’s subprocess class

Actually, that’s much smarter than what I suggessted!

Snail0259 | 2021-07-10 22:25