Local API for Game Control

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

I’m making a bot for an open-source single-player game I like. I’ve pulled the game down from git and now:

I want to patch in an API so the bot can control the game without a mouse and keyboard and get some graphical info in text form.

Can someone point me in the right direction?

:bust_in_silhouette: Reply From: Calinou

There are a few ways to go around this, but the easiest way is likely to host a WebSockets server from the Godot project. Godot offers a WebSocketServer class for this (and additionally a WebSocketClient class too).

You can then use any command-line WebSocket client to interact with the running project.

Alternative methods include:

  • Using an HTTP server written in GDScript (and using that as a base for a REST API).
    • HTTP clients are more prevalent than WebSocket clients, but HTTP is a slower option especially if you need to send/receive data frequently.
  • Creating a custom TCP server using Godot’s TCP_Server class.
  • Creating a custom UDP server using Godot’s PacketPeer class.