Jump to content

GetKey("name") ?


Gabriel
 Share

Recommended Posts

i try to get in Lua script my instance name with GetKey("name") but return a nil value

 

...
function class:CreateObject(model)
   local object=self.super:CreateObject(model)

   AppLog(object.model:GetKey("name")) --    <-- return nil ?
...

 

object.model:GetKey("position") work !

 

how to get my instance name ?

 

 

 

PS: in file Class.lua at function object:GetKey as no process for the key "name"!

Link to comment
Share on other sites

Hi

i will try to help sorry if it is not the best way to do it

 

you need to SetKey("name") = "myname" in the Class construction CreateObject(model)

 

and to have properties in editor you can put

 

function class:InitDialog(grid)
self.super:InitDialog(grid)
group=grid:AddGroup("General")
group:AddProperty( "Name", PROPERTY_STRING )
end

 

of your mymodel.lua

 

then from your main loop you can retrieve the name of your entity with

	for m_entity in iterate(CurrentWorld().entities) do 

		if m_entity:GetKey("name") == "myname" then
--you got your entity
                       end
               end

 

hope it helps

AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11

Link to comment
Share on other sites

If you are just looking to retrieve the object model's assigned name, then you have to wait for it to be set after creation of the object. This template object script will show basically the order in which the automatic object functions get called:

test_template.zip

Note that the GetKey function is called repeatedly while the model is selected, so just place the model into the scene then click off of it to unselect it, then look at the console log to see the order of the functions.

 

As for retrieving the object model's assigned name, try this:

require("scripts/class")
local class=CreateClass(...)

function class:CreateObject(model)
       local object=self.super:CreateObject(model)

function object:UnlockKeys()
	AppLog("name of object: "..self.model:GetKey("name"))
end

function object:Free()
               self.super:Free()
       end
end

 

Also, just to point it out, but you are posting in the Leadwerks3D forum, an engine that has not been released yet. Your lua programming topics should be posted here: LE2 Lua

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

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