Jump to content

Recommended Posts

Posted

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.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

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

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

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

 

My job is to make tools you love, with the features you want, and performance you can't live without.

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...