From 4bcc3948532f88f974f38ff4abd7def7ba27ef66 Mon Sep 17 00:00:00 2001 From: Juraj Paluba Date: Sat, 19 Oct 2024 01:10:05 +0200 Subject: [PATCH] docs: create GeneralsIO client example The with block is important, thats how the websocket connection is automatically handled. It can be ommited by instiantiating the GeneralsIOClient directly, but it will require manual call for disconnect. For details, see: https://python-socketio.readthedocs.io/en/latest/client.html#creating-a-client-instance --- examples/client_example.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 examples/client_example.py diff --git a/examples/client_example.py b/examples/client_example.py new file mode 100644 index 0000000..cc5f1f6 --- /dev/null +++ b/examples/client_example.py @@ -0,0 +1,11 @@ +from generals.agents.random_agent import RandomAgent +from generals.remote import GeneralsIOClient + + +if __name__ == "__main__": + agent = RandomAgent() + with GeneralsIOClient(agent, "user_id9l") as client: + # register call will fail when given username is already registered + client.register_agent("[Bot]MyEpicUsername") + client.join_private_game("queueID") + client.wait_for_game()