Jump to content

GetKeyValue name for prefabs


klanphear
 Share

Recommended Posts

Hello, I am trying to check the world for a prefab entity. I can retrieve the names for model entities but not the prefabs. If I change the name of the prefab(returning it to a model) it will get said value. I am trying to write a script in Lua to check if the "FPSPLayer" is present in the world, if the player is not present then create a camera. If I check for a model entity and it is present the camera is not created, if not present it creates the camera, so I know my script works just not for any prefab item. I have tried several prefabs with no avail. Models return "name" just fine.

 

I found a function posted by Rick and modded it to use on a pivot with a key-press, thanks for all your posts have learned a lot. ty to all others who help in the forum also.

 

function Script:Start()

end

function Script:UpdateWorld()
if window:KeyHit(Key.I) then self:FindEntity() end
end

function Script:FindEntity(entityName)
local x
local world = World:GetCurrent()
for x = 0, world:CountEntities() - 1 do
			 local entity = world:GetEntity(x)
System:Print("name = "..entity:GetKeyValue("name"))
			 if entity:GetKeyValue("name") == entityName then
return entity
end
end
return nil
end

 

if I run this the output is listed below. I have the player prefab and controller prefab in the scene. I noticed CSG objects do not appear also with the exception of the Arch 1 which I did not rename.

 

Loading shader "C:/Users/klanp_000/Documents/Leadwerks/Projects/test/Shaders/Model/Shadow/shadow.shader"...

Loading shader "C:/Users/klanp_000/Documents/Leadwerks/Projects/test/Shaders/Lighting/directionallight.shader"...

name =

name =

name =

name =

name =

name =

name =

name =

name =

name =

name = controller

name =

name =

name = generic

name = firepit

name = brick

name = Pivot 2

name = Arch 1

name = track_loader

name = Directional Light

Process Complete.

 

any help appreciated, ty kirk

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...