Josh Posted August 19 Posted August 19 If you need to split up a Lua file for any reason, you can use require to load a table (or any other value) from another file. The included file will only be run once. Here, I use require to store a component function in another file. Motion.zip Extract this to "Source/Components/Motion" if you want to use it. This probably requires the beta branch to run correctly. When you use the require command, you are loading a Lua module. This is slightly different from an include file, and can be used to load both Lua scripts and DLLs. Thus, you should not specify the file extension when using this command...just a strange detail of the more advanced Lua functionality. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Josh Posted August 20 Author Posted August 20 You can also simply copy a function from one table to another: local t = {} function t:Update() if self.globalcoords then self.entity:Translate(self.movementspeed / 60, true) else self.entity:Move(self.movementspeed / 60) end self.entity:Turn(self.rotationspeed / 60, self.globalcoords) end Mover = {} Mover.name = "Mover" Mover.movementspeed = Vec3(0)--"Movement" Mover.rotationspeed = Vec3(0,1,0)--"Rotation" Mover.globalcoords = false--"World space" Mover.Update = t.Update RegisterComponent("Mover", Mover) return Mover Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Josh Posted August 20 Author Posted August 20 This would also work: function MyUpdateFunction(self) if self.globalcoords then self.entity:Translate(self.movementspeed / 60, true) else self.entity:Move(self.movementspeed / 60) end self.entity:Turn(self.rotationspeed / 60, self.globalcoords) end Mover = {} Mover.name = "Mover" Mover.movementspeed = Vec3(0)--"Movement" Mover.rotationspeed = Vec3(0,1,0)--"Rotation" Mover.globalcoords = false--"World space" Mover.Update = MyUpdateFunction RegisterComponent("Mover", Mover) return Mover Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.