Scott Richmond Posted December 5, 2009 Share Posted December 5, 2009 Take a look at windmill.lua: --Include the base script for all classes dofile("Scripts/base.lua") --Some global sounds we will use for all instances squeak={} squeak[0]=LoadSound("abstract::squeak_1.ogg") squeak[1]=LoadSound("abstract::squeak_2.ogg") --This function builds the interface for the properties editor function InitDialog(grid) <SNIP> end --Spawn function for creating new instances function Spawn(model) local entity=base_Spawn(model) --Retrieve a few limbs we will use later entity.blades=model:FindChild("windmill_blades") entity.base=model:FindChild("windmill_housing") entity.model:SetKey("spinspeed","1") --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() <SNIP> end end --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 entity:Update() end end end end 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? Quote 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 More sharing options...
Rick Posted December 5, 2009 Share Posted December 5, 2009 There is a need to run code every cycle so this is just how Josh decided to do it. Quote Link to comment Share on other sites More sharing options...
Scott Richmond Posted December 5, 2009 Author Share Posted December 5, 2009 But why create another Update function? Why not just put the code under the default Update function? Quote 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 More sharing options...
Rick Posted December 5, 2009 Share Posted December 5, 2009 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. Quote Link to comment Share on other sites More sharing options...
Scott Richmond Posted December 5, 2009 Author Share Posted December 5, 2009 Ahh, I see. No problems then. Thanks Rick. Quote 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 More sharing options...
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.