Jump to content

LUA Entity:Update Function Help

Scott Richmond

Recommended Posts

Take a look at windmill.lua:

--Include the base script for all classes

--Some global sounds we will use for all instances

--This function builds the interface for the properties editor
function InitDialog(grid)



--Spawn function for creating new instances
function Spawn(model)
local entity=base_Spawn(model)

--Retrieve a few limbs we will use later

--An update function for one instance. Declaring the function as part of the entity table allows us to use "self" for the table
function entity:Update()




--Update function, called during every UpdateWorld()
function Update(world)
if world==world_main then
	local model,entity
	for model,entity in pairs(entitytable) do
		if model.world==world then


Now I understand that the Update(world) function is run at every tick automatically by LE. What I don't understand is why this script redirects the Update() function to this custom entity:Update() function. Is there a specific reason for this?

Programmer, Modeller

Intel Core i7 930 @ 3.5GHz | GeForce 480 GTX | 6GB DDR3 RAM | Windows 7 Premium x64

Visual Studio 2008 | Photoshop CS3 | Maya 2009

Website: http://srichnet.info

Link to comment
Share on other sites

Because it makes the code "cleaner". I think he should have named it something else besides Update() because it can look confusing. In his other scripts he does stuff like UpdateTires() which makes more sense. In some scripts you might want to do 4 different things and putting all that inside Update() will mess that method up.

Link to comment
Share on other sites

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.

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...