Game Development Community

ContainerFindFirst freezes Torque

by Daniel Buckmaster · in Torque Game Engine · 03/29/2008 (4:19 am) · 6 replies

I'm using containerFindFirst in my AI scripts to find enemies near a squad. When I call it with the wrong number of arguments, I get console warnings. When I call the right number of arguments, the engine freezes on mission load.
This is rather annoying.

I suspect the problem may be using the function in a loop. Is this correct notation?
for(%found = 0; %found = containerFindFirst(%mask, %position, %range, %range, %range); %found = containerFindNext())

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!


#1
03/29/2008 (5:00 am)
Have you debug what is the %position and range value ?

Aun.
#2
03/29/2008 (8:33 am)
%range is 100
%position is "float float float" (forgot the values but they were correct)
I think the problem is that it's looping infinitely - I don't know the functions well enough to put them in the loop properly :P
#3
06/05/2010 (11:55 am)
I think you would want to use something like
%found0 = containerFindFirst(%mask, %position, %range, %range, %range);
for (%i = 1; %i < $MaximumNuberOfObjectsToFind; %i++)
{
   eval("%found" @ %i @ " = containerFindNext();");
}

This will set values such as the following:
%found0 = 1227;
%found1 = 1802;
%found2 = 1356;
%found3 = 1284;
#4
06/05/2010 (12:51 pm)
@ Daniel:

The "for" structure looks like this:
for (initialize var; condition to loop; increment var)

The conditional code is checked for each loop. containerFindFirst initializes the search and returns the first result. That's something you only want to call once; not on every loop. The code you posted results in a hung system because you are asking the engine to restart the search for each loop iteration. What you're looking for is something like this:

for (%found = containerFindFirst(%mask, %position, %range, %range, %range); %found != 0; %found = containerFindNext())

... Jonathan's solution is workable, but it imposes a hard limit on the number of items that can be found.
#5
06/09/2010 (7:43 pm)
Cheers Scott and Jonathan - not sure if I ever solved that problem, but looking back on it now I see how silly it was ;P. No idea what I was thinking at the time!
#6
06/10/2010 (12:06 pm)
Heh. I thought it was a curiously rookie question for you! I should have thought to check the date stamp, but I didn't. Only later did I realize Jonathan bumped a 2 year old post. :-P