Jump to content

GetEntity() feature request


Rick
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

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

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?

Link to comment
Share on other sites

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

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

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...