martyj Posted July 24, 2015 Share Posted July 24, 2015 I have several entities that I'm trying to get a reference to a bunch of entities to be able to spawn copies of them. All my entities are at the same location. (-100, -100, -100). My code is as follows function ParseWorldItemsCallback(entity, extra) local name = entity:GetKeyValue("name") System:Print("name:"..name); end function ParseWorldItems() local aabb = AABB(-101, -101, -101, -99, -99, -99) local world = World:GetCurrent(); world:ForEachEntityInAABBDo(aabb, "ParseWorldItemsCallback", nil); end My problem is that the name of the entity is empty string "". Am I using ForEachEntityInAABBDo wrong? Or is there something wrong with how I'm getting the entity name? Thanks, Marty Quote Link to comment Share on other sites More sharing options...
holschuh Posted July 24, 2015 Share Posted July 24, 2015 hi your aabb is nothing, both Points of the aabb box are in the same Location - very small box you scan. cu Volker Quote Link to comment Share on other sites More sharing options...
martyj Posted July 24, 2015 Author Share Posted July 24, 2015 Sorry my mistake, I was messing around with that to see if it was the AABB that was the problem. I changed the code back to had I first had it. That doesn't change the entity name problem I am having. Both versions get entities passed to the callback. The problem is their name is empty. Quote Link to comment Share on other sites More sharing options...
holschuh Posted July 27, 2015 Share Posted July 27, 2015 Hi, you have to set the "name" key first for each entity you want maybe in an other script attached to this entities. do in new script in the start section an self.entity:SetKeyValue("name","something") cu Voiker Quote Link to comment Share on other sites More sharing options...
beo6 Posted July 27, 2015 Share Posted July 27, 2015 Are you using Prefabs? maybe you have these issues i reported here: http://www.leadwerks.com/werkspace/topic/13055-prefabs-not-working-correctly/ the name key should also be set with the editor name field. No need to set it in code again. Quote Link to comment Share on other sites More sharing options...
martyj Posted July 27, 2015 Author Share Posted July 27, 2015 I am not using prefabs. The name is set with the editor. I believe the two may be related though. Quote Link to comment Share on other sites More sharing options...
holschuh Posted July 27, 2015 Share Posted July 27, 2015 Hi, the Name in the LE Editor cannot proofen with GetKeyValue("name") Try to set the key by code.(SetKeyValue("name","entity1")) http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetkeyvalue-r774 cu Volker Quote Link to comment Share on other sites More sharing options...
beo6 Posted July 27, 2015 Share Posted July 27, 2015 it should work, and as you see in my report, it sometimes work. but sometimes not. So it must be a bug. Quote Link to comment Share on other sites More sharing options...
BluHornet Posted July 30, 2015 Share Posted July 30, 2015 The easier and less costly way is to make a table of prefabs, ie. PreFab{}, and then place a dummy of each in a distant place on the map with the editor to preload them at start. when you want one to be called (copied) just use the PreFab:Load(). this also lets you randomize spawns. If you have 5 zombie models you can call a math:random(1,5) and pass that as the table position and randomly pick the prefab to add some coolness. I have done this for mobs as well as items for drops before. It looks like this assuming you have populated a PreFab table with paths to the entities you want to spawn. local random = math(1,5) local spawn = PreFab:Load(PreFab[random]) spawn.SetPosition(whateverPos) spawn.SetRotation(whateverRot) spawn.script:Start() you could copy the entity but if something happens to your master the copy will be messed up. with the preload you don't have that issue because you are making a fresh one when you need it but all the assets are already in memory because of the dummies. 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.