Jump to content

Rick

Members
  • Posts

    7,936
  • Joined

  • Last visited

Posts posted by Rick

  1. Could we get a 2D drawing function that gets called automatically from the engine/editor? This should be pretty easy to do I would think. It's just like Update(), but this would be right before the Flip() method. It would work just like the other functions in that if it doesn't exist for an object it just doesn't get called. This would allow us to make 2D objects that people could plug-n-play via the editor that would provide huds and gui controls. I think this would go well with the new single state model as other objects would probably require data and feed data to these. I know a possible solution currently would be to do something like billboards but it would be nice to have this option also.

  2. The crappy part currently is that it would require a change to the fps and other "game" scripts. If Josh made each entity call a 2D draw function in the correct place by default then we shouldn't have to require changes to these and it would make it easier. I'll make a feature request for it.

  3. he said he was doing it in fpscontroller.lua... nothing about an entity.

     

    in any case he can do it in that code just like I did in the example02.lua...

     

    but aggror, i wouldn't use the mouse positions for your locations of the drawn image... the fpscontroller's "mouse" is always in the center of the screen right? so just draw the hand texture in the center of the screen.

     

     

    He can, but how much cooler would it be to be able to distribute an entity that you can just drag & drop into the editor and have it do 2D stuff. People could make 2D HUDs and interfaces that we can just drop & drag into the editor. Now that's cool.

  4. Where are you doing this? In the main loop right before Flip() or in an entity? Remember that 2D needs to be done right before the Flip() statement so really an entity can't handle this right now. I think Josh should create a function that gets called per entity right before the Flip() so it can though. You could probably do this though by adding some code in the fps code. Loop through all entities and if the function Draw2D() exists call it. Then in the entity you want to do this add a Draw2D() function.

  5. I just copied the light and commented the light specific stuff out.

     

    dofile("Scripts/base.lua") -- We need the base class entity
    
    function InitDialog(grid)
    base_InitDialog(grid)
    --group=grid:AddGroup("Light")
    --group:AddProperty("Resolution",PROPERTY_CHOICE,"256,512,1024,2048")
    --group:AddProperty("linearoffset",PROPERTY_FLOAT,"0,1,2","Linear offset")
    --group:AddProperty("multoffset",PROPERTY_FLOAT,"0,1,2","Multiplicative offset")
    --group:AddProperty("Range",PROPERTY_FLOAT,"1,100,0")
    --group:Expand(1)
    end
    
    function Spawn(model)
    local entity=base_Spawn(model)
    entity.model=model
    --entity.light=CreatePointLight(10,model)
    
    entity.pivot = CreatePivot()
    return entity
    end
    
    function GetKey( model, key, value )
    local entity=entitytable[model]
    if entity==nil then return value end
    if entity.model==nil then return end
    
    return base_GetKey(model,key,value)
    
    --if entity.light==nil then
    	--return base_GetKey(model,key,value)
    --else
    	--if key=="linearoffset" then
    	--	return entity.light:GetShadowOffset(0,0)--..","..entity.light:GetShadowOffset(0,1)..","..entity.light:GetShadowOffset(0,2)
    	--elseif key=="multoffset" then
    	--	return entity.light:GetShadowOffset(1,0)--..","..entity.light:GetShadowOffset(1,1)..","..entity.light:GetShadowOffset(1,2)
    	--elseif key=="range" then
    	--	return entity.light:GetRange()
    	--else
    	--	return base_GetKey(model,key,value)
    	--end
    --end
    end
    
    function SetKey(model, key,value)
    local entity=entitytable[model]
    if entity==nil then return 1 end
    if entity.model==nil then return 1 end
    
    base_SetKey(model,key,value)
    
    if entity.light==nil then
    	--base_SetKey(model,key,value)
    else
    	--if key=="resolution" then
    	--	if value=="0" then
    	--		entity.light:SetShadowmapSize(256)
    	--	elseif value=="1" then
    	--		entity.light:SetShadowmapSize(512)
    	--	elseif value=="2" then
    	--		entity.light:SetShadowmapSize(1024)
    	--	elseif value=="3" then
    	--		entity.light:SetShadowmapSize(2048)
    	--	end
    	--elseif key=="range" then
    	--	entity.light:SetRange(value)
    	--elseif key=="shadowresolution" then
    	--	resolution=entity.light:GetShadowmapSize()
    	--	if resolution==256 then
    	--		return 0
    	--	elseif resolution==512 then
    	--		return 1
    	--	elseif resolution==1024 then
    	--		return 2
    	--	elseif resolution==2048 then
    	--		return 3
    	--	else
    	--		return -1
    	--	end
    	--elseif key=="multoffset" then
    	--	entity.light:SetShadowOffset(entity.light:GetShadowOffset(0,0),value,0)
    	--elseif key=="linearoffset" then
    	--	entity.light:SetShadowOffset(value,entity.light:GetShadowOffset(1,0),0)
    	--else
    	--	return base_SetKey(model,key,value)
    	--end
    end
    
    return 1
    end
    

  6. I still have something funky about my custom pivot entity. After the first time I save the scene and close it then reopen no matter where I move it and save the scene again, closing the editor and reopening it the pivot will always go back to where it was originally saved.

  7. What is happening there?

     

    I assume the editor calls light_directional_CreateClass(). Which defines the other functions in the class table and then returns the class table to the editor, which then can call the functions defined inside light_directional_CreateClass? So I assume the editor will save off the class table per model in the scene so it can call the functions defined in it. It's not the worst just seems the light_directional_CreateClass() function should be more of a class. I'm just used to C++ more than lua, but I get what it's doing.

     

    Do we have access to the preprocessor? I might try to make something just for myself and the scripts I create.

  8. I agree, fewer lines that I have to type the better. Your example of how to do it however isn't much fewer. I was more thinking of some kind of preprocessor macro stuff to make things look easier. Not sure if lua has that sort of thing.

  9. Is there any way that can be cleaned up somehow? 3 nested functions SetKey() and everything needs to be in a nested function Create() just seems kind of messy. Even if this is how it has to be, there might be a way to hide some of this so it looks more straight forward.

  10. OK I'm confused as to what is happening here. I'm trying to create a GetEntityByName(name) function. In it, it will loop CurrentWorld().entities looking for the key name you pass in. So step one I just want to print all entity names.

     

    for model in iterate(CurrentWorld().entities) do
    	Print("Searching name.. "..model:GetKey("Name"))
    end
    

     

    The thing I don't get is if I put this in the Update() method it prints all the entities, BUT if I put this in a function that gets ran just once from inside Update() (it's like an init thing inside Update() where it'll only run the function inside and if statement) in my log all I see is 1 line of "Searching name... ". It's blank.

     

     

    [EDIT]

    Here is the code in monster truck lua

     

    How it's setup below I see Inside test print in the log but no entities looped through in the log. If I uncomment the GetEntityByName("test") in the Update() method it does loop through all entities. So what's the difference?

    function Test()
    Print("Inside test")
    GetEntityByName("Rick")
    end
    
    function Update(world)
    local model
    local entity
    for model,entity in pairs(entitytable) do
    	entity:UpdateTires()
    end
    
    if(init == false) then
    	if(GetGlobalNumber("game") == 1) then
    		--Print("Running MyScript")
    		init = true
    		--RunScript(MyScript)
    		Test()
    	end
    end
    
    --for m in iterate(CurrentWorld().entities) do
    --	Print("Searching name.. "..m:GetKey("Name"))
    --end
    
    --GetEntityByName("test")
    
    UpdateCR()
    end
    

  11. So I copied the light entity to make a pivot entity. The name property doesn't seem to stick. I set it, click apply, close the properties window, and when I go back in the name is blank again. What needs to happen for these properties to hold their value?

  12. That doesn't seem to work. I have this code in the Update of vehicle_monstertruck.lua and that is in my scene. When I open up the scene I have saved with this code in it I get "attempt to call global 'iterate' (a nil value)" error.

     

    Did you make the iterate function in lua? If so what lua file?

  13. So how would I get the name property of the entities while looping through them?

     

    I'm trying the below with no luck. I also tried a few variations of this but still no luck

    for entity in iterate(CurrentWorld().entities) do
        Print("Entity name = "..entity.model:GetKey("name"))
    end
    

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

  15. light_directional_InitDialog=base_InitDialog

    light_directional_Spawn=base_Spawn

    light_directional_GetKey=GetKey

    light_directional_SetKey=SetKey

    light_directional_ReceiveMessage=base_ReceiveMessage

    light_directional_Kill=base_Kill

     

    That looks to be about the only new thing. You could probably encapsulate that with a function call.

     

    Maybe like:

     

    InitEntity("light_directional")

     

     

    You should be able to do:

    function InitEntity(ent)

    _G[ent.."_InitDialog"] = base_InitDialog

    ...

    end

×
×
  • Create New...