User:NXTBoy/Lua Issues
Naming Inconsistencies
Casing on Object and class members seems to be arbitrary. Some members, like Ray.Origin
are UpperCamelCase, while others, like Vector3.x
, are lowerCamelCase. At present, there seems to be no logic behind this whatsoever, and its leads to messy and error-prone code. The there are the members like Instance.getChildren
, which are valid in both casings with no clear documentation on which one is deprecated.
Instead, a convention should be adopted. This could take the form of:
- Members of
Instance
s are always of the same capitalization - Members of lua data objects, such as
CFrame
andVector3
, are always of the same capitalization
Draconian error handling for absent object properties
Part.ChildThatMayOrMayNotExist
current returns an error if ChildThatMayOrMayNotExist
does not exist. It would be generally easier to handle if a nil value were simply returned. To aid new scripters, a warning could be issued in the command bar. This should be extended toward every object that currently throws a error when an unset value is retrieved.
Modularity
Currently, modularizing a script is much harder than it should be. There are a couple of things that hinder this:
- LocalScripts vs Scripts - If one wants a utility function to exist on both the client and the server, then two identical scripts must be created, and put in different types of Script in different places. Clearly, this is bad for maintainability
- No tidy way to require a library be loaded before running a script
In my opinion, the solution to this would be:
- Create a service in DataModel for storing library scripts, sorted hierarchically into "Packages"
- Create a new type of script called LibraryScript
- When the place loads, run ALL the scripts in the library service on both the client and the server. Would be good if global variables could be synced as well
- When a script requires a library, add a
require "geometry.MyAwesomeNewVector"
to the top. This will delay the scripts execution until the corresponding library is loaded. If all libraries in the ScriptLibraryService have been loaded, and it is still not found, then error