Given that Lua is not giving me any help in the form of compile time type checking, it would be really great if I didn’t have to guess what part of this line of code was wrong:
If it was an instance, it would’ve said “not a valid member of Part or whatever”.
This undescriptive errors happens because you’re indexing a non-instance userdata.
That could be a CFrame, a Vector3, … (your ‘s’ isn’t a part, which is what you want I assume)
Line numbers are displayed in the stacktrace.
(no idea what you mean with “caret position”, I assume “that character there”)
Just having “CFrame is not a valid member of Vector3” would already help a lot.
At least you know you’re trying to index a Vector3 instead of an Instance or table or whatever you wanted.
That would be slightly more helpful, but I think it might be possible to get the name of the variable out of the stack. I haven’t done any Lua API stuff since December though.
Yeah, that is built into Lua. I would be surprised if I didn’t have access to the same information, but you never know until you look!
EDIT: Upon review, I’m not sure it is possible. Especially given the case where the object being indexed is an rvalue (by that I mean “Color3.new(1,1,1).x”, what happens then?) If I figure out another way, I’ll try it. Spoke too soon. Will check it out later.
Hmph, I don’t think getting the name of the variable is possible. It turns out that Lua actually parses the bytecode or something when it actually gets you the name of the variable you failed to index.
However, it would be slightly more helpful if the error messages included the typename. I’ll check into that, it would be very easy.
It uses the debug data in the bytecode.
If you can replicate the “get variable type/name” that happens on indexing a nil/number value, it’ll work fine.
That would be best, as doing print(game.Banana) errors “Banana is not a valid member of DataModel”. (“attempt to index/call …” is for “pure Lua errors”, not something “C-sided” like Instance methods)
Hm, I just don’t think there’s a feasible way. Most uses will be on a temporary anyway, like part.CFrame.badIndex. I did, however, add a typename for all of the ROBLOX userdata types just now!