Putting Objects Into Strings
Posted: Wed Mar 13, 2019 11:55 pm
So I had recently got my game to sort-of work with multiplayer. My problem now is that I have Lua objects that need to be communicated to/from the server/client. So, I need to come up with a mechanism that takes the objects needed and turns them into strings, and another for taking strings and putting them into programmatic objects.
I have been piggybacking off of the LOVE physics, which is great. I use a lightly modified version of Hero ( https://github.com/airstruck/hero ) along with JSON ( https://github.com/rxi/json.lua ) to send/receive the physics world.
Since I have been programming for single player, I haven't designed the game objects to be friendly with tostring. Every physical item in the game has one body, one shape, and one fixture, just as an FYI. I used the setUserData/getUserData methods from Body, and either had a nil or table value for all body's userdata values. The problem was that not all the values would tostring, so I had to comment out the userData section of Hero.
My plan is to create a class for the userData values, and create an object specifically for handling userData for each body. My problem is that I am trying to think how to best-possible enforce code that makes sure that all values can be converted into strings. Any thoughts, or do I need to add some clarity to what I'm trying to get across?
I have been piggybacking off of the LOVE physics, which is great. I use a lightly modified version of Hero ( https://github.com/airstruck/hero ) along with JSON ( https://github.com/rxi/json.lua ) to send/receive the physics world.
Since I have been programming for single player, I haven't designed the game objects to be friendly with tostring. Every physical item in the game has one body, one shape, and one fixture, just as an FYI. I used the setUserData/getUserData methods from Body, and either had a nil or table value for all body's userdata values. The problem was that not all the values would tostring, so I had to comment out the userData section of Hero.
My plan is to create a class for the userData values, and create an object specifically for handling userData for each body. My problem is that I am trying to think how to best-possible enforce code that makes sure that all values can be converted into strings. Any thoughts, or do I need to add some clarity to what I'm trying to get across?