I’ve been working on my space game for quite some time now, and I ended up using EgoMoose’s WallStick module because it easily allows me to let players be on separate moving planets without worrying too much about the physics engine.
However, there is a downside to this module, and it’s that it relies heavily on the client to work. This means that in order to keep everything up to date and functional clientside, I need to be sending a lot of data from the server.
One very important piece of data is a list that contains the states and orbital parameters of every part being affected by my custom gravity controllers. However, when I send this list over to the client, the indexes, which are the instances being affected by gravity, don’t get passed.
This list is extremely crucial to my current data structure, and I rather not rework it if I don’t have to. What methods can I take to pass the data to the client?
If I am interpreting your question correctly, I believe that Collection Service is something that might benefit you here. It allows you to attach tags to Instances which can then be called from Server or Client, and thus allows you to call those items as an array/table. This is useful in scenarios such as attaching a single function to many of the same object, however will work most likely for what you need.
It seems Collection Service can only attach strings to instances, but the data I’m trying to send with instance indexes aren’t only strings. Is there a way to get around this?
Thinking about it now, I can probably set a tag with a designated index and send the data over, but I also have some instances (primarily the planet the instance is orbiting) that I’m trying to send too.
I guess I should make the data structure a little clearer, this is the data structure I’m working with:
GravityList[Instance] = {Data = table with metatable (essentially a custom class, different metatable for different gravity types), Parent = the body that the instance is orbiting, Type = string of type of gravity, Children = list of instances whose Parent property in this list is this Instance}
I’ll have to take a moment to look over the WallStick module, as I have never used/seen it before. It will give me a more clear understanding of the data structure. I find it difficult when I don’t have a script to diagnose haha. A few moments please, unless someone else replies first.
Actually let me just clarify something, as this doesn’t seem to be a problem inherent with the module, but rather a request for a way to send data across the Cli - Serv Boundary, and some of it won’t send because it is actual objects?
No, it’s not a problem with the module, the module is working as intended. It’s just the difficulty in getting data to the module from the server, as the module works almost exclusively in the client. I already have a module set up to facilitate this server to client interaction, it’s just this extra data that’s hard to get
To be SUPER clear, you are attempting to send tables with metatables from client to server or vice versa?
If that is the case, it is one of the Parameter Limitations of Remotes
Huh, ok. I was sending metatables through, but I haven’t tried interacting with them yet so I guess I didn’t notice. Thanks for the warning. Thinking about it now, all that I really needed from that gravitylist, atleast so far, is the gravity type, So I guess I can use collection service for that for now. I’ll still have to look for a solution later down the road when I do need those metatables and parent/children properties, but I can keep working for now.
Alright, so I guess I can store the gravity type and extra parameters in tags, and recreate the metatable when necessary on the client. That just leaves the parent and children properties left. We’re making progress
Correct me if I’m wrong, but I thought sending mixed tables in remotes ends up in losing the mixed part of the table. I’ve never dealt with this myself since I’ve avoided using objects as keys but I remember some warnings regarding table behaviour in client-server interactions.
Yeah, I’m realising that problem now, and I’ve learned it’s at the core of this issue. Using collection service, I can probably get by using instances as strings, but I’m still passing more instances in the data.
Just want to make sure you understand Collection Service. You aren’t converting the Instances to strings, you are attaching non visible strings that act as markers. Then you can use a function of the service to call the tag name which is a string, and that will give you those objects that are tagged with it. It will be a table of references to the objects themselves.
Oh, I was just going to add a tag with the related gravity type to the instance, pass non-instance data over, and recreate the table on the client side without instance indexes, but I still didn’t know how to pass related instance data. But if I understand what you’re saying, is that I should tag the instances that I want to send over in relation to another instance with a tag that is unique to both the related instance and property name. My only concern now is how do I get a unique string to identify an instance with, as I’m not confident that every instance in my game will always have unique names.
The amount of time you wrote Instance in that makes me so confuzzled. I think you and I are on the same wavelengths here, however I ALSO think the problem, is probably much simpler than we are making it seem. Lay out exactly, using an example of a planet with a name and whatever data you need as names, and the things you need sent over. This, OR code would greatly assist me in being able to assist you.
I’ll try an example, Let’s say I have a planet called Planet, and a satellite called Satellite. The satellite is orbiting the planet in on rails ‘orbit’ mode, all I need to recreate the table and metatable on the other side is the satellite and planet, which I would be sending anyways, and the 10 numbers that are unique to its orbit. On the satellite, I add the tags “Orbit” to specify the type, and a second tag with some string unique to that instance which I’ll call ‘stg’ for now, on the planet, I tag ‘stg Parent’, on the other instances that might be orbiting the satellite, I tag ‘stg Child’. I send the 10 numbers and stg to the client through a remote event. The client searches for instances tagged with ‘stg’, ‘stg Parent’, and ‘stg Child’ to complete the data it needs. The only thing I need now is a method of generating a unique string to serve as ‘stg’. However, I can probably just use numbers passed through tostring() increasingly as more instances are processed to get that unique string, maybe with a prefix to specify this tag is unique to the orbit management system.
I’m going to try and lay this out as bullets for myself
There is a planet called “PLANET”
There is a Satellite named “SATELLITE” (As in a man made machine orbiting the planet where we bounce signals from in space, and not the meteorological definition of satellite)
SATELLITE is orbiting PLANET on rails in (sidenote: this was written in on rails above, so correct me if I am incorrect about correcting this bit) in ‘orbit’ mode
Only thing needed is the reference to that specific planet and satellite (named PLANET and SATELLITE) (which can already be sent across in the remote?)
Your solution is
Onto SATELLITE I add the tag “Orbit” to specify the type (type of what?)
I also add a second tag with some string unique to that instance (unique to SATELLITE) which we will call stg
Onto PLANET I tag ‘stg Parent’,
on the other instances that might be orbiting SATELLITE, I tag ‘stg Child’.
I send the 10 numbers and stg to the client through a remote event. The client searches for instances tagged with ‘stg’, ‘stg Parent’, and ‘stg Child’ to complete the data it needs.
The only thing I need now is a method of generating a unique string to serve as ‘stg’. This part confuses me, why does it need a unique string? What is the unique string for?
However, I can probably just use numbers passed through tostring() increasingly as more instances are processed to get that unique string, maybe with a prefix to specify this tag is unique to the orbit management system.
My real question is, are meta tables even necessary to this system? Can you envision a way to do this entire thing without metatables? Don’t get me wrong here meta tables have great uses, and are future compatible if you want to change some core aspect of your game system 2,3 years into the future. Sometimes though, a simpler solution works better just because of the aforementioned limitations of the boundary. For example, if it were me, I would simply send a single dictionary through to the client which contained all of my necessary information, and then use that to create whatever it is I had to create. Collection Service CAN be used as you described above, however, if you are creating a new tag for each unique item, you are using the Service incorrectly. The tags are meant to be global arrows pointing to the Objects/Instances that are tagged with them. Think of them as color coding paperwork. You have a bunch of payment forms, so they all get tagged with ORANGE, you also have a bunch of Math Homework, so you give the papers that are math homework, the BLUE tag. Then when you need to look through all these identical looking papers, you can sort them by finding the Blue and the Orange tag. If you need any other properties or unique Identifiers after that, you can just add values to them on the server, and only ever check those values on the server.
I guess I should have mentioned my orbit types. This game actually started out as a way for me to learn about orbital mechanics, or specifically the two body system, and the first orbit type I made is what I like to call an ‘on rails’ mode, where the orbitting body isn’t effected by any other physics object or forces, it just follows a set path, like train rails, as defined by its Keplerian Elements. It was the first mode I made, and is used for actual orbits, that’s why it’s labeled ‘Orbit’, my other modes are ‘PartGravity’, for making a physics object be attracted to a planet just using a vector force, and ‘PlayerGravity’, which uses the WallStick module to keep the player on the planet. Hopefully that clears up any confusion.
I made the metatables for many reasons. First because I wanted to work with OOP, which I feel greatly improves my ability to understand my own code, and makes me feel like my code is more modular and adaptable to future plans. I don’t have much in the game right now, but I have a lot of radically different ideas (most of which are inspired from SS13 and KSP) in which I can take the game, and leaving the systems less set in stone will help me implement new ideas. The metatables also contain a lot of helpful functions, and help sort my code into different packages. The ‘Orbit’ metatable has about 21 functions dedicated to manipulating data to compress everything I need to find the position and velocity of the planet at any time, future or past, into just 10 numbers (and because I have these functions, if I wanted to save space, I could do it in 6), which allows me to not have to constantly run physics calculations in the background for every object in space. All of these features really makes me not want to give up the metatables.
I guess I’m using Collection Service incorrectly here, but I don’t see why this would be that much of an issue. I don’t see how adding these tags for client -server interaction would interfere with using Collection Service normally at the same time, and if it doesn’t take up that much more memory, and makes the workspace a little cleaner then spamming Object Values everywhere, I’m happy with it.
I appreciate your help with this issue. I can’t believe we were going at it for 3 hours. I’m going to sleep now, as I have school in the morning, so I might not be able to respond any more for tonight, but I’ll see if I can check on this topic again in the morning before classes start. Thanks again for the help.