To add onto that, every time i attempt to print the vectors they just return as 0,0,0?? I don't know why this is happening or what it means, can someone please explain.
Id prefer to save vectors because its easier than saving 3 variables at a time.
Vectors have a metatable attached to them, which adds, among others, a __name field that defines it as a vector type, and a __tostring field that makes it print the coordinates in the table instead of the generic table: 1234abcd format. Use textutils.serialize to format them as a table for output, or store the three values in a new table, and recreate the vector (which retains the metatable on load, unlike serialization).
local vector_as_string = textutils.serialize(vec)
local vec_back = textutils.unserialize(vector_as_string)
setmetatable(vec_back, getmetatable(vector.new()))
The metatable part just allows you to do vec_back:normalize() (and other vector operations), since serializing doesn't save metatables.
Yes. Most lua values are serializable. Exceptions are functions, threads, and tables with either of these in them. Userdata as well, but you shouldn't run into that type within CC.
Tables with metatables can be serialized, but you'll need to reset the metatable upon reloading like I did with the vector in my previous comment (assuming your table/object supports this).
Memory address, I only recently installed CC and haven't taken the time to learn Lua yet but I'm assuming you need to serialize the structure to a string like you would in Python?
2
u/theredstonewyven Jul 16 '24
To add onto that, every time i attempt to print the vectors they just return as 0,0,0?? I don't know why this is happening or what it means, can someone please explain.
Id prefer to save vectors because its easier than saving 3 variables at a time.
2
u/JackMacWindowsLinux CraftOS-PC & Phoenix Developer Jul 16 '24
Vectors have a metatable attached to them, which adds, among others, a
__namefield that defines it as avectortype, and a__tostringfield that makes it print the coordinates in the table instead of the generictable: 1234abcdformat. Usetextutils.serializeto format them as a table for output, or store the three values in a new table, and recreate the vector (which retains the metatable on load, unlike serialization).1
u/Bright-Historian-216 Jul 16 '24
That’s hexadecimal, likely a pointer to the location of the table in memory
1
u/popeh Oct 12 '24
Memory address, I only recently installed CC and haven't taken the time to learn Lua yet but I'm assuming you need to serialize the structure to a string like you would in Python?