Gabriel Posted November 7, 2011 Share Posted November 7, 2011 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"! Quote Link to comment Share on other sites More sharing options...
diedir Posted November 7, 2011 Share Posted November 7, 2011 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 Quote AMD Ryzen 5900HX - Nvidia RTX 3070 - 32 Go - 1To SSD - W11 Link to comment Share on other sites More sharing options...
macklebee Posted November 7, 2011 Share Posted November 7, 2011 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 Quote 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 More sharing options...
Gabriel Posted November 8, 2011 Author Share Posted November 8, 2011 Oups sorry and thank ;-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.