Jump to content

Josh

Staff
  • Posts

    23,313
  • Joined

  • Last visited

Posts posted by Josh

  1. This should work to set globals in the Lua virtual machine:

    Function SetScriptObject(name:String,o:Object)
    Local size:Int=GetStackSize()
    lua_pushbmaxobject(luastate.L,o)
    lua_setglobal(luastate.L,name)
    SetStackSize(size)
    EndFunction
    
    Function GetStackSize:Int()
    Return lua_gettop(luastate.L)
    EndFunction
    
    Function SetStackSize(size:Int)
    Local currentsize:Int=GetStackSize()
    If size<currentsize
    	lua_pop(luastate.L,currentsize-size)
    EndIf
    EndFunction

  2. I usually like to have a lot of extra checks:

    function class:CreateObject(model)
    
    local object=self.super:CreateObject(model)
    object.cube=CreateCube()
    
    function object:Free()
    	if self.cube~=nil then
    			self.cube:Free()
    			self.cube=nil
    	end
    	self.super:Free()
    end
    
    end

     

    Don't forget self.super:Free()!

  3. I added a vcproject to the Transparency and Refraction lesson. I'm going to include a project with each lesson showing the final result.

     

    Unfortunately, the Windows 64-bit Program Files convention interferes with this, because the project doesn't know if the header files are in C:\Program Files\Leadwerks Engine SDK or C:\Program Files (x86)\Leadwerks Engine SDK. I am going to make these projects with the header in C:\Leadwerks Engine SDK, and the default installation directory will be moved there as well.

  4. If you add require("scripts/loop") at the top, you will import the loop script, which has a few functions declared the engine picks up:

     

    require("Scripts/hooks")
    
    function UpdateWorldHook()
    RunHooks("UpdateWorld")
    end
    
    function UpdatePhysicsHook()
    RunHooks("UpdatePhysics")
    end
    
    function FlipHook()
    RunHooks("Flip")
    end

     

    I just added the FlipHook() function, so I guess it doesn't make sense to call this file "loop" anymore. Maybe "enginehooks" would be a better file name?

     

    Then the user can use AddHook("UpdateWorld",myfunction) to add their own Lua hooks, and your main loop doesn't have to have any code hardly.

  5. You could but the results would be unpredictable because SetMatrix() updates the entity position, rotation, scale, etc.

     

    Here is a list of members:

    http://leadwerks.com...ntities#Members

     

    The following are the documented members of the Entity class. Generally, members should be treated as read-only. For example, setting the entity position by changing the position vector values will fail to perform necessary updates the SetPosition() command would call, and the results may be unpredictable.

×
×
  • Create New...