Hi all,
I would like to embed a Python Shell running certain Python code in my PlayCanvas game. How can I go about making a UI for the Python code, while the core logic remains with unchanged and still uses Python?
Hi all,
I would like to embed a Python Shell running certain Python code in my PlayCanvas game. How can I go about making a UI for the Python code, while the core logic remains with unchanged and still uses Python?
Sounds like it’s one or more of the following problems you are trying to solve here:
You are best off doing this in HTML. It’s possible to do this with the PlayCanvas UI (someone from our forums has made a text input field for the PlayCanvas UI system) but it be trying to dig with a spoon. It’s doable but it’s the wrong tool for the job.
You will have to find either a Python interpreter that’s been written in JS, a service where you can send Python code to and get a result or setup your own server to run Python code on to get the result.
You will have to write some sort of binding between PlayCanvas and Python. This might mean you have to run a server that your PlayCanvas app listens to and does ‘stuff’ pending on what Python code is sent to the server.
Can you tell me how to do 3?
High level wise.
Get a remote server (e.g Gcloud, Digital Ocean, Heroku)
Install a Python runtime
Install something that allows you to define a web API (e.g. Node.js)
Create a REST API that allows you to send Python code to it
Now the tricky part is how to connect your PlayCanvas app to it. You could do something as simple as the server returning a JSON result that the app interprets and runs a series of logic/animation from. Or something as complicated as allowing the PlayCanvas app to connect to the remote server using something like websockets and listening for events to react to.