Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:57:48+00:00 2026-06-10T17:57:48+00:00

I would like to add some scripting to my models/actors. When a new model

  • 0

I would like to add some scripting to my models/actors. When a new model gets loaded, or a script is changed, the actor reacts.

For now, I have a base Lua class which has, for example, a Update() function and each model/actor should overload this function. But how to implement it? The main problem is that each model needs a unique name for the class,…

  1. I was thinking of a table whose key values are the actorID(unique) and the value would be a class inherited from the baseclass, but it’s a bit difficult when the script gets reloaded.

    Objects[ActorID] = Model(paramater)

    Objects[ActorID].Update = function() print("Update: actor 1") end

  2. Maybe it’s also possible to create a new lua state for each actor.

I got the inspiration for this, from the Leadwerks engine: http://www.youtube.com/watch?v=z-EuS1EYk8o

If anyone knows a good book for scripting in game engines please tell me

I think i got it:

Here is some pseudo code:

OnNewActorCreated:

//Add actor
Objects[param.ID] = createClass(baseclass)

//Check if this actor has a script to run.
if param.hasScript then

   //Add the new ID to the script
   Scripts[param.filename][param.ID]

   Entity = Objects[param.ID]

   doFile(param.filename)

   Entity = nil

end

OnFileChanged:

foreach id in Scripts[changedfile] do

    Entity = Objects[id]

    dofile(changedfile)

    Entity = nil

end

Example Script:

//check if Entity is valid
if not Entity then
   print("[Error] Entity is invalid")
else   
    function Entity:Update() 
        print(self.name)
     end
end

Could work 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:57:50+00:00Added an answer on June 10, 2026 at 5:57 pm

    The way the engine in the youtube video works does not rely on an overloaded Update function. The reason they have base classes is to provide default behavior and a common interface to their objects, but is not related to actually updating anything.

    They are using functionality presented by the OS to listen for file updates (see this SO question for more info on that) and then simply execute the script in the game’s lua_State. Since the scripts only modify the type definitions (tables and metatables), when you reload the script (via simple luaL_dofile or equivalent I presume) the new definitions overwrite the old ones and lua happily chugs along using the updated behavior. If you really squint and look at the code the video shows in the editor, you’ll notice they are just defining functions, as opposed to running Update methods.

    As a final note – if you create new lua_States for each actor, then you will lose the ability to freely pass things around between them in Lua, and will have to write C++ code to manually pass data between two (or more) lua_States.

    Edit: With regards to inheritance from a common base object: modifying its metatable will alter the behavior of all objects, so we need to protect against that. One way would be to surround the entity script with guards against modifying the actual common metatable. Before loading the script we save a reference to the base metatable and replace it with a copy that can be used by the script.

    In this way the script does not need to create its own metatable and does not need to know how the rest of the engine will refer to it. Instead it just uses the Entity one. Once the script is done defining it’s derived behavior, we can give its copy of Entity a new name (one based on the name of the script file, the name of the world object, etc.) and restore Entity to the original reference.

    Aside from the above, we gain the added benefit of not persisting changes through different updates. Every time we want to change the script during runtime, we repeat the process and can be confident that if something was added in a previous update it will not remain after we execute an update that removes it. If we simply let the script overwrite metatables, then we cannot remove functions and members without explicitly setting them to nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add some paragraphs or new lines or words dynamically but
I would like to add some JavaScript inside Blogger. <script type=text/javascript> window.open(http://www.page.html, myWindow, status
I would like to add some scripting support to a Silverlight 4 application that
I would like to add some logic to my model to ensure there is
When creating a new file with vim, I would like to automatically add some
I would like to add some background music to the splash screen in the
I would like to add some custom data to an image the user generates
I would like to add some data to the body of a http request
I would like to add some interactive capability to a python CLI application I've
I would like to add some debugs for my simple ruby functions and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.