Rick Posted December 1, 2009 Share Posted December 1, 2009 I think a GetEntity(name) function would be very helpful. With each model class script kind of being on an island (since they all use their own lua states) a way to get any loaded entity from anywhere could be beneficial. This should be possible if GetEntity(name) is a C function that is exposed to lua from the executable. In the executable every entity is available so it should be that hard to give all scripts access to any entity. The name parameter would be a key setting called "Name". So if I add a model to my scene and set the name property to "Rick" I should be able to access that entity in a different model class lua file by calling: GetEntity("Rick") I know Targets() can be used for this, but setting all sorts of targets for all different kinds of interactions gets cumbersome and error prone. Would be better to just be able to call 1 function to get the entity. I would think this would be an easy feature to add and give a ton of help to us. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Share Posted December 1, 2009 The point of targets is so you don't have to type in unique names and find them later. Just click and drag between two models. Unique names are more error-prone. Target relationships won't run into problems with redundant names. You can set up one system of objects, then copy and paste them, and the copied group will behave the same, with targets intact. If you copy and paste named objects, their names will be identical, and they will interfere with each other. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Author Share Posted December 1, 2009 Would be nice to have both options. That wouldn't hurt anything would it? Also some way to loop through all entities would be nice. Let's say I want to create an entity that acts on all other entities. I would have to drag all entities to my entity to create a target. That would be a pain. I just think these things provide more flexibility. How many targets can you have? Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Share Posted December 1, 2009 It would hurt something, because it would cause more bugs for me to spend time on. The biggest problem would be if two models have the same name, and then one is freed, there would be no model for that name, even though it exists. You can have up to 8 targets. I can raise that if needed, but it seemed like enough for now. You can loop through all entities with the world entity list: for entity in iterate(CurrentWorld().entities) do end Or: for entity in iterate(CurrentWorld().models) do end Or: for entity in iterate(model.reference.instances) do end Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Author Share Posted December 1, 2009 Perfect! I'll create my own GetEntity() using CurrentWorld().entities and looking at a name property if one exists. That way the bugs will be on my plate and not yours. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 1, 2009 Share Posted December 1, 2009 Don't use it in real-time, because iterating through the whole model list will be slow when there are lots of models. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 1, 2009 Author Share Posted December 1, 2009 I'll stress test it. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 5, 2009 Author Share Posted December 5, 2009 So how would I get the name property of the entities while looping through them? I'm trying the below with no luck. I also tried a few variations of this but still no luck for entity in iterate(CurrentWorld().entities) do Print("Entity name = "..entity.model:GetKey("name")) end Quote Link to comment Share on other sites More sharing options...
Josh Posted December 5, 2009 Share Posted December 5, 2009 for model in iterate(CurrentWorld().entities) do Print("Entity name = "..model:GetKey("name")) end Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted December 5, 2009 Author Share Posted December 5, 2009 That doesn't seem to work. I have this code in the Update of vehicle_monstertruck.lua and that is in my scene. When I open up the scene I have saved with this code in it I get "attempt to call global 'iterate' (a nil value)" error. Did you make the iterate function in lua? If so what lua file? Quote Link to comment Share on other sites More sharing options...
Nilium Posted December 5, 2009 Share Posted December 5, 2009 That doesn't seem to work. I have this code in the Update of vehicle_monstertruck.lua and that is in my scene. When I open up the scene I have saved with this code in it I get "attempt to call global 'iterate' (a nil value)" error. Did you make the iterate function in lua? If so what lua file? It's in the linked list script. Quote MacBook Pro 15.4", Intel Core 2 Duo T9600 2.80GHz, 4GB 1066MHz DDR3, GeForce 9400M 256MB, GeForce 9600M GT 512MB - Mac OS 10.6.2, Vista32 Link to comment Share on other sites More sharing options...
Rick Posted December 5, 2009 Author Share Posted December 5, 2009 Perfect, thanks. Couldn't find it. 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.