Pygbag post request #120
-
Hi, I am working on a game in pygame, with the plan of deploying it using pygbag. I need to be able to save the game results to a secured server, preferably through sending a POST request to an API. I have been able to integrate that into the Python file, but have not been successful in sending the request using the converted file. I have tried using both urllib and requests in the base python file. My understanding is that I would need to integrate JavaScript into the HTML file and send the request that way. Is this feasible, keeping in mind that I need to trigger the POST request once the game is finished? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
there's aio.fetch.RequestHandler for that pygbag/pygbag/support/cross/aio/fetch.py Line 191 in 6fef0c9 That code was extracted from a scoreboard experiment written by @tank-king but has no test for it right now. Please report back any problem. for posting on exit it is quite tricky : some platform may allow to close tabs without any warning or callback. You should background that task but as soon as possible / make a "saving" screen animation like most modern games have. side note: maybe implement some proof of game while game is running and save incrementally game state. because some people could just make arbitrary post request to the server. |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to do something similar with databases, like get an asset from a mongodb or make an authenticated request to a service listening via REST API? |
Beta Was this translation helpful? Give feedback.
there's aio.fetch.RequestHandler for that
pygbag/pygbag/support/cross/aio/fetch.py
Line 191 in 6fef0c9
That code was extracted from a scoreboard experiment written by @tank-king but has no test for it right now. Please report back any problem.
for posting on exit it is quite tricky : some platform may allow to close tabs without any warning or callback. You should background that task but as soon as possible / make a "saving" screen animation like most modern games have.
side note: maybe implement some proof of game while game is running and save incrementally game s…