GML How to pack/unpack binary strings?

hippyman

Member
I play a game called Live for Speed that has a couple cool programming toys you can mess with (InSim, OutSim, OutGauge). I know how to connect to servers and the basics of creating/sending/receiving packets and from my understanding, I need to send a binary formatted string to the server, then the server responds with another binary string.

That's where my problem begins. The getting started tutorials say that I need to send a binary formatted string to the game, but I have no idea how to make that in GMS. I was hoping somebody who is familiar with Python can tell me exactly what is happening when you use the function struct.pack. My hope is that by understanding how a binary string is packed/unpacked, I'll be able to do it with GML.

Any help would be greatly appreciated!
 

Anixias

Member
Edited 10/28/2020: I used to be stupid and over-confident in my abilities. This comment sucked.
 
Last edited:

hippyman

Member
I'm not making a game. I'm trying to interact with another game. I have no choice in the matter of what I send to the server. As I mentioned, I know the basics of interacting with networks in GMS. I'm asking for somebody to explain to me what a binary string is. What makes it different from just a normal string? What makes it different from a binary number? I just though binary was only numbers so I don't even know what a binary string is.
 
R

rui.rosario

Guest
I just looked at that Python reference and a binary string is nothing more than bytes together as a string. So in GMS you could have the buffer with values 0 16 7 15 an in Python that would be '\x00\x10\x07\x0f'. It then looks that on the Python side there are some fomat strings to indicate how to interpret the string and I just quickly looked at the reference but you can also specify endianness for reading the bytes (although if not specified it seems like it uses the system's default).
 

hippyman

Member
So I guess my solution would be to make a script that creates a string with those '\x' delimiters in between every single byte. Now that I took a break and came back to this, I think it wouldn't be too difficult to create a quick small framework for something like this.

I should also mention that I'm not trying to communicate with a python server. I'm just trying to do something with GML that you can do with Python. The documentation says I can use whatever language I want to communicate with the LFS network. I just wanted to make sure there wasn't a misunderstanding.
 
R

rui.rosario

Guest
Well, if they expect those string literals then yes, it would be as simple as converting the buffer's contents to the escaped binary string
 

hippyman

Member
Is it not possible to read from a buffer byte by byte? I've checked the different functions and they seem to only allow to read for specific data types.

My current idea is to make a temporary binary file and write the data to it then read back the data byte by byte and inserting the delimiters and then send that as a buffer_string. I'll have to test it to see how well it performs since I don't think this is very efficient.
 

hippyman

Member
Turns out I was making things WAAAAY more difficult than they need to be. I tried sending what I assume was a binary formatted string and it didn't work, but then I just sent the buffer with the data and it worked. The LFS InSim tutorial made me think that it was required to send a binary string but I think when they say that they just mean a buffer. Regardless of all that, I'm getting things moving now. Thanks for the help though!
 
Top