Page 1 of 1

Sending Data/World to/from users

Posted: Sat Dec 15, 2018 5:16 am
by EliterScripts
Hello,
So I am working on a game that heavily uses love.physics, and have been programming for the client. However, I plan to start programming for the server, and am not sure what to do for this, since I have to fit either the World object into a string, then into Lua-enet, then taking the string and back into a World object, and stuff like that where I try to get a non-traditional object into a string, (I have a table with all the fixtures, bodies and shapes) however Lua doesn't seem to like any of the methods I've tried where I to shove an object into a string.

Now, I did search through the forums to find an answer:
but these answers are outdated, and don't have any downloads to them. It's a dead end.

I want to avoid having to go into the fixture/body/shape and manually pull all the data possible, put them into a string, then into a JSON object. I am very much able to create JSON objects with this library: https://github.com/rxi/json.lua . On the other hand, I want to have a standardized client/server protocol, so I can create a Python client for being an Artificial Intelligence playing the game, so it would be nice to not be bound to Lua/LOVE for running the game on the client-side. Of course, I will have real players use LOVE2D client, but I'm planning to use Python for AI/NPC's, no graphics will be used for Python.

Re: Sending Data/World to/from users

Posted: Sat Dec 15, 2018 10:12 am
by pgimeno
I doubt that sending the whole world in every packet is going to be a viable solution, but if you want to try, there's Hero, a Library to Save the World: viewtopic.php?f=5&t=82591. I don't know how well it works with latest LÖVE; you may need to do some updates. You'll also need a serialization module to serialize the resulting table; maybe dkjson if you want JSON.

For more fine-grained serialization suitable for syncing that avoids sending the whole world every time, this library will probably help better: viewtopic.php?f=5&t=85981

Disclaimer: I don't give support for any of these. I just remembered them from the forums, in a "if I ever need this, now I know where to look" sort of way. I'm using dkjson myself in one of my projects, which doesn't mean it suits your purpose, of course.