View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:30 am



Reply to topic  [ 5 posts ] 
 Object group statement? 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Object group statement?
Ok, I want that all objects in a specific group are affected by a certain function, but I am in doubt about the exact syntax I should use.

Should it be something like:

for actor in MovableMan.Actors and actor in MovableMan.GroupName do

I am rather confused, as I read the lua documentation and found very little reference to group functions. Any help would be appreciated. Thanks in advance. :)


Wed May 20, 2009 9:41 pm
Profile WWW
User avatar

Joined: Mon Feb 11, 2008 3:42 pm
Posts: 259
Reply with quote
Post Re: Object group statement?
Not sure which GroupName you're referring to, but your syntax is a little off.

Code:
for actor in MovableMan.Actors do
will do something for all actors.

for whatever GroupName you have in mind,
Code:
for actor in MovableMan.GroupName do
should suffice, as long as the group is in fact in MovableMan.


Wed May 20, 2009 10:49 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Object group statement?
I think I didn't express myself correctly.
What I mean is that, in the .ini file, I give an actor an AddToGroup = XYZ variable. Then, in the .lua file, I want the game to iterate through all the objects in group = XYZ. The problem is that XYZ is not a predefined group in MovableMan, but a custom group. So, any ideas?


Thu May 21, 2009 9:01 pm
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Object group statement?
actor:IsInGroup("XYZ") returns true if it is in group XYZ.
So, if everything in the group is actors, the code would go like so:
Code:
for actor in MovableMan.Actors do
   if actor:IsInGroup("XYZ") then
      <code>
   end
end

Or, if you wanted to cycle through every type of object (including particles and weapons):
Code:
for actor in MovableMan.Actors do
   if actor:IsInGroup("XYZ") then
      <code>
   end
end
for item in MovableMan.Items do
   if item:IsInGroup("XYZ") then
      <code>
   end
end
for particle in MovableMan.Particles do
   if particle:IsInGroup("XYZ") then
      <code>
   end
end

This is of course assuming the code changes according to object type. Otherwise, you'd just declare a function and call it where <code> would normally be.


Thu May 21, 2009 11:51 pm
Profile WWW
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Object group statement?
Yes! It works! :lol:
Thanks!

I've gotta tell you, it's fun using lua to stop missiles in mid-air and send them back to the poor soldier who shot them... :P


Fri May 22, 2009 1:16 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.514s | 13 Queries | GZIP : Off ]