rain_gloom Posted July 30, 2013 Share Posted July 30, 2013 could someone (preferably crystalMV) write an in depth tut about the string types and the uses of the script or direct me to one? Link to comment
DiSaMe Posted July 30, 2013 Share Posted July 30, 2013 There are no "string types", the script simply converts the numeric and string data into a string which looks like the same values stored in RAM or HDD. Format argument (the first values passed to dataToBytes and bytesToData functions) describes what data you store/retrieve. For example, if you want to store two 2-byte integers v1, v2 and a 4-byte integer v3 (all signed and little-endian), this is how it would look like: local packed = dataToBytes("ssi", v1, v2, v3) "s" means a 2-byte integer and "i" means a 4-byte integer. So it's "s" for v1, another "s" for v2 and "i" for v3. And now the string packed contains a string whose length is 8 characters. First two bytes contain the value of v1, the following two bytes contain v2 and the last four bytes contain v3. If type identifiers in the format string are repeating, you can put a number before the letter instead of repeating it. In this case, you can substitute "ssi" with "2si". Now, when you need to get the values from the string packed, you need to use bytesToData with the same format string and it will return the values which were passed to bytesToData: v1, v2, v3 = bytesToData("ssi", packed) If my explanation wasn't good enough, you could try reading this: http://docs.python.org/3.3/library/struct.html . I made the functions to work like struct.pack and struct.unpack in Python do. By the way, it looks like the example in my website has some mistakes. Also, I noticed that while the floating point data works on standalone Lua interpreter, it gives incorrect results on MTA client (not sure about the server). This is probably because of reduced mathematical precision of calculations on the client. So I hope that's enough info for you Link to comment
rain_gloom Posted August 19, 2013 Author Share Posted August 19, 2013 thx a lot so all I have to remeber is the data types Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now