Jump to content

Nilium

Members
  • Posts

    22
  • Joined

  • Last visited

Profile Information

  • Location
    Not entirely sure

Nilium's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Nilium

    2.3 Sync

    1. New Scene 2. Create terrain: 512x512, 4 meters 3. Sculpt the terrain a bit, just need some minor bumps, really 4. Add two road nodes Things cease to work as expected right about there. I would attach an example SBX, but it won't let me.
  2. Nilium

    2.3 Sync

    Think this looks like a bug? Not entirely sure if it's the script or what. Seems like it'd be the script, though...
  3. Nilium

    2.3 Sync

    Seems the update didn't work all too well first time around. Oh well, working (in a sense, anyway) now.
  4. Nilium

    2.3 Sync

    Can anyone point out where StripAll is? 'Cause the class script is using it, but it certainly does not exist. Undecided about filing it as a bug.
  5. Nilium

    Why Apple Fails

    You can say a Mac is for folks without brain cells, or that it's for people who have no clue about computers, but y'know that nice code that lets you work with Lua the way you can now? Written on a Mac by a Mac user. At any rate, good job alienating one of the people offering you help in getting Lua working.
  6. Try adding error("<" .. type(modelreference) .. "> " .. tostring(modelreference), 1) right after you set modelreference. I'd be interested in knowing exactly what shows up as the error message there.
  7. I don't see anything in the script that would cause that error, and assuming your Lua type's methods are essentially one-to-one wrappers around the existing API, I don't know that there's a problem with that. Probably an error in another script.
  8. What does the script look like now? Also, what is the string value?
  9. Forgot about the modelreference bit. Add local modelreference = ... just after the require line. Could also do local class = CreateClass(...). Also, when checking the result of luaL_loadfile, luaL_dofile, etc. you check to see if the result is zero, not if it's non-zero (so, result=0 means no errors), so that's also an error in your code there. Out of curiosity, Josh, do you have a Google Wave account?
  10. Replace the 'class=nil' bit at the end of that script with 'return class' and use luaL_loadfile like so: lua_pushstring(L, entity_class_name+"_CreateClass") ' e.g., light_directional luaL_loadfile(L, path_to_entity_script) ' loads the script as a Lua function lua_settable(L, LUA_GLOBALSINDEX) ' sets the global light_directional_CreateClass to the function
  11. A preprocessor sounds like a horrifyingly bad idea. Woops, editing stuff in the post window tends to do that.
  12. What would your solution be? Personally, I see nothing wrong with this, aside from a bit of unnecessary code. E.g., in SetKey, all you'd need is this: function object:SetKey(key,value) if key=="resolution" then local value = tonumber(value) if 0 <= power and power <= 3 then object.light:SetShadowmapSize(256 * 2^power) end else return self.super:SetKey(key,value) end end This probably comes down to coding style, however, but I like having fewer lines. Far as I'm concerned, nested functions in Lua are fine. You wouldn't have to put everything in Create, for one - you could store it in a local and reference that in the function, like so: require "scripts/class" do local function table_merge(table, into) for k,v in next, table, nil do into[k]=v end end -- object methods local object_methods = {} function object_methods:SetKey(key,value) if key=="resolution" then local power = tonumber(value) if 0 <= power and power <= 3 then object.light:SetShadowmapSize(256 * 2^power) end else return self.super:SetKey(key,value) end end function object_methods:GetKey(key,value) if key=="linearoffset" then return object.light:GetShadowOffset(0,0)..","..object.light:GetShadowOffset(0,1)..","..object.light:GetShadowOffset(0,2) elseif key=="shadowdistance" then return object.light:GetShadowDistance(0)..","..object.light:GetShadowDistance(1)..","..object.light:GetShadowDistance(2) else return self.super:GetKey(key,value) end end function object_methods:Kill(model) if self.light then self.light:Free() self.light = nil end self.super:Kill() end -- class methods local class_methods = {} function class_methods:InitDialog(grid) self.super:InitDialog(grid) group=grid:AddGroup("Light") group:AddProperty("Resolution",PROPERTY_CHOICE,"256,512,1024,2048") group:AddProperty("linearoffset",PROPERTY_VEC3,"0,1,2","Linear offset" ) group:AddProperty("shadowdistance",PROPERTY_VEC3,"","Shadow distance" ) group:AddProperty("Range",PROPERTY_FLOAT) group:Expand(1) end function class_methods:Spawn(model) local object=self.super:Spawn(model) object.model:SetKey("resolution","2") object.light=CreateDirectionalLight(object.model) table_merge(object_methods, object) return object end -- light_directional_CreateClass function light_directional_CreateClass(modelreference) local class=CreateClass(modelreference) table_merge(class_methods, class) return class end end
  13. I'm making a bunch of assumptions about how you're doing this, but I'm going to assume I'm right. ' doing this longhand so exactly what is going in is more apparent (synonymous with lua_getglobal(L, "entitytable")) lua_pushstring(L, "entitytable") ' stack => -1 = "entitytable" lua_gettable(L, LUA_GLOBALSINDEX) ' stack => -1 = entitytable ref lua_pushbmaxobject(L, model) ' stack => -2 = entitytable ref, -1 = model object ' get the "entity" table stored in "entitytable" (similar names make these examples confusing as hell) lua_gettable(L, -2) ' stack => -2 = entitytable ref, -1 = entity ref ' remove the "entitytable" reference since it's unneeded lua_remove(L, -2) ' stack => -1 = entity ref ' longhand (synonymous with lua_getfield(L, "SetKey", -2)) lua_pushstring(L, "SetKey") ' stack => -2 = entity ref, -1 = "SetKey" ' get SetKey method lua_gettable(L, -2) ' stack => -2 = entity ref, -1 = function ' then push the "entity" table to the top of the stack so it will be the 'self' parameter lua_pushvalue(L, -2) ' stack => -3 = entity ref, -2 = function, -1 = entity ref (self argument) ' remove entity ref at -3 lua_remove(L, -3) ' stack => -2 = function, -1 = entity ref (self argument) ' push a key and value ' by now the stack should be something like -4 = function, -3 = entity ref (self argument), -2 = key argument, -1 = value argument lua_pcall(L, 3, 0, 0) ' stack => either nothing left or -1 = error string if there was an error The code highlighting on this forum desperately needs a 'turn the hell off' option.
  14. lua_getglobal(L, "referencetable") ' I'm assuming the "reference" table should be a local here, so not in the globals table lua_pushnumber(L, 3) ' push the key lua_gettable(L, -2) ' get the value ' or with an object: lua_getglobal(L, "classtable") ' _G["classtable"] lua_pushbmaxobject(L, modelreference) ' modelreference lua_createtable(L, 0, 0) ' {} lua_settable(L, -3) ' classtable[modelreference]={} lua_pop(L, 1) ' remove the table from classtable from the stack Not sure I see the problem. Maybe you're mistakenly thinking that the only way to get values out of/put values in a table is with lua_get/setfield?
  15. It's in the linked list script.
×
×
  • Create New...