Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Iterate Through All Entities in a Scene  (Read 4136 times)

0 Members and 1 Guest are viewing this topic.

Finn

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
Iterate Through All Entities in a Scene
« on: October 03, 2006, 03:23:18 AM »

Hi,

Anyone have any suggestions on how I cycle through all the entities in a scene without knowing what they might be? I use a particular entity naming convention and want to apply certain code to all entities that, for example, have a name that starts with 'abc' (there could be 'abc1', 'abc2', 'abc_i_am_a_monkey', etc.).

Part of this will probably involve using the Substring method.

I've looked through the docs but nothing's jumping out at me. What I need is a collection or array or similar to work with. Is there some sort of a variation of GetNode?

Cheers.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Iterate Through All Entities in a Scene
« Reply #1 on: October 03, 2006, 06:46:33 AM »

You can do something like this to iterate all entities in the main layer of the scene:

Code: [Select]
var MainLayer = Scene.MainLayer;

// process all entities in the main scene layer
for(int i=0; i<MainLayer.NumNodes; i=i+1)
{
   var Node = MainLayer.GetNode(i);
   if(Node.Type=="entity") DoSomething();
}

Similarly, if you wanted to process all layers, you'd use another loop and Scene.NumLayers / Scene.GetLayer().
« Last Edit: October 03, 2006, 06:48:06 AM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Finn

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
Re: Iterate Through All Entities in a Scene
« Reply #2 on: October 03, 2006, 01:08:45 PM »

Thanks Mnemonic - exactly what I was looking for!

WME didn't like the 'int' declaration in the for line.
Code: [Select]
for(int i=0; i<MainLayer.NumNodes; i=i+1)
Replaced it with 'var' instead and works a treat.
Code: [Select]
for(var i=0; i<MainLayer.NumNodes; i=i+1)
« Last Edit: October 03, 2006, 01:19:47 PM by Finn »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Iterate Through All Entities in a Scene
« Reply #3 on: October 03, 2006, 01:22:27 PM »

Hehe, oops, C-programmer's subconscious typo :)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

leucome

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 86
    • View Profile
    • Leucome Games
Re: Iterate Through All Entities in a Scene
« Reply #4 on: October 06, 2006, 05:31:46 AM »

I wish to know if it is posible to do it with the actor3d ?
Logged
Look my Site ——► http://news.leucome.ca

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Iterate Through All Entities in a Scene
« Reply #5 on: October 06, 2006, 07:17:00 AM »

I wish to know if it is posible to do it with the actor3d ?
No, it only applies to "static" scene content. Since you're loading 3D actors dynamically, you'd have to keep track of them yourself, like storing them in some array when loading them etc.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

leucome

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 86
    • View Profile
    • Leucome Games
Re: Iterate Through All Entities in a Scene
« Reply #6 on: October 06, 2006, 08:14:10 PM »

I am curently using some array to keep track but i will need to do some test with Snene actor and Game actor ... Because now they are separated in my script ...
Logged
Look my Site ——► http://news.leucome.ca

jbw

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 24
    • View Profile
Re: Iterate Through All Entities in a Scene
« Reply #7 on: January 22, 2007, 04:26:44 PM »

Yes, I can iterate all entities in all layers, but what about FREE entities? They aren't belong to any layer, so how to get them?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Iterate Through All Entities in a Scene
« Reply #8 on: January 22, 2007, 08:25:29 PM »

You don't. There's currently no way of querying free entities other then using Scene.GetNode("entity_name"). For that, of course, you need to know the name of the entity you're looking for.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.077 seconds with 24 queries.