kills686 Posted April 6, 2015 Share Posted April 6, 2015 Hello everyone, I am trying to get a count of how many crates i have but am having a hard time figuring out how to refer to them directly to get a proper count. I want to do this to be able to track crates as i get rid of them and to add in new ones as they are generated. Thanks for any help! Quote Link to comment Share on other sites More sharing options...
macklebee Posted April 6, 2015 Share Posted April 6, 2015 You could perform a count of world entities and then cycle through confirming name, but i would assume that would be too expensive and might cause a noticeable pause in the game when adding or removing. One way might be to add a script to the crate model that checks for a global table (or creates the table if it doesn't exist) that adds the crates entities to it. Then all you would have to do is count the number of items in the table. When the crate is removed from the scene then the script can use the function Script:Detach() to decrement the table. 1 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...
kills686 Posted April 6, 2015 Author Share Posted April 6, 2015 @macklebee I think that would work. Is there anyway i could get an example of the table creating function and the referencing of the specific object? Sorry I'm still pretty green behind the ears. Thanks again for the help! Quote Link to comment Share on other sites More sharing options...
macklebee Posted April 6, 2015 Share Posted April 6, 2015 http://www.leadwerks.com/werkspace/page/tutorials/_/script/introduction-to-lua-scripting-r103 1 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...
Genebris Posted April 6, 2015 Share Posted April 6, 2015 I was looping through all entities in the world each update in my map script and didn't notice any fps drops, so I think it's good enough. Something like this: for i=0,App.world:CountEntities()-1 do local entity = App.world:GetEntity(i) if entity:GetKeyValue("name") == "Crate" then --this is your crate entity, can count it or delete end end Strange that CountEntities and GetEntity aren't in documentation, they are very important. 2 Quote Link to comment Share on other sites More sharing options...
kills686 Posted April 8, 2015 Author Share Posted April 8, 2015 Thank you both for the help! These are great ideas and should ease my struggles Also @Genebris I searched the documentation and was looking for those exact ideas but ended up trying count child which of course did not work lol 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.