tipforeveryone Posted February 14, 2016 Share Posted February 14, 2016 This is my Scene Tree If I attach a script to "CSCDSoldier" then I can write something to do to its child (ex: mp5sd) by using self.entity:FindChild("mp5sd"):GetPosition() or in case, script is attached to "mp5sd", I still can get "CSCDSoldier" by using self.entity:GetParent():GetPosition() But how can I get "CSCDSoldier" even "mp5sd" from script which I attached to "Player" I did not find anything like self.entity:GetSiblings("CSCDSoldier"):GetChild("mp5sd") in the API Reference Library Please show me how. Thanks Quote Link to comment Share on other sites More sharing options...
josk Posted February 14, 2016 Share Posted February 14, 2016 The simple way is if you add Script.Enemy = nil --entity at the top of player script. If you highlight player in the scene tree and look at players script tab. Then drag CSCDSoldier from the scene tree to the empty Enemy box. You can then access CSCDSoldier by using self.distance = self.entity:GetDistance(self.Enemy) //self. distance is an example or even some variable on CSCDSoldier script for example self.TakeHit was in that script. self.Enemy.script:TakeHit(self.damage) This way you can also access CSCDSoldier's child items. The following are worth looking at as well. self.entity:SetKeyValue("item","name") self.target:GetKeyValue("item") 1 Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
tipforeveryone Posted February 14, 2016 Author Share Posted February 14, 2016 I created all objects in Editor and rename them I want to access them from anywhere without using Script.variableName = "" --entity "Label" Example: I press Q key to make an entity disappear ìf window:KeyDown(Key.Q) then GetSomeThingByNameFunction("EntityName"):DoSomeThingFunction() end Just simple like that I need to put this code to main.lua so that I can't use the '--entity' method I guess Quote Link to comment Share on other sites More sharing options...
Rick Posted February 14, 2016 Share Posted February 14, 2016 I make a utility function for this when I need to. Note that every entity you use this for should be a unique name or else this will just get the first one. You could modify it if you want to get all entities with the same name to have it add to a table and return the table. function 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 2 Quote Link to comment Share on other sites More sharing options...
tipforeveryone Posted February 15, 2016 Author Share Posted February 15, 2016 Wow thank you Rick. This works perfectly. You show me all that I need. Hope someday there will be an official function like yours in Leadwerks (Josh?) 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.