PDA

View Full Version : Unable to execute IF loop, no idea why.



DMarkwick
Aug 15 2009, 21:50
I'm testing a couple of methods for fire propagation, I got one method sort of working but it's pretty flaky. However, for this test I'm trying to maintain an array of all destroyed trees in the mission, and using that to check if the current tree is to be burned.

But, I cannot work out why the code inside the loop will not execute:


if (!(_objID in JTD_FireTrees)) then
{
hint "JTD_FireTrees loop";
nul = [_x] execVM "ForestFireTree.sqf";
JTD_FireTrees = JTD_FireTrees + [_objID];
sleep 5;
};
?

_x being the tree currently being tested. The loop works with the other method (testing for proximity of a custom object) and I'm not getting errors in the rpt. _objID definitely exists, 'cos I hint it just before the loop. JTD_FireTrees is initialised in the config like this:

JTD_FireTrees[] = {};
and yet the loop never executes. I never see the inner hint.

JTD_FireTrees is an array that all destroyed trees will go in, and objID is the ID number of the currently tested tree.

.kju [PvPscene]
Aug 16 2009, 05:41
You cannot use in that way for a if query.
http://community.bistudio.com/wiki/in_Array

you need to use this


_found = false;

{
if (_objID == _x) then { _found = true; };
} forEach JTD_FireTrees;

if (!_found) then
{
...

DMarkwick
Aug 16 2009, 18:45
Well, I got it to work by first ensuring that the array JTD_FireTrees was not empty. Apparently it doesn't like searching empty arrays :)

So I just make the array = [1,2] and it's happy :)

.kju [PvPscene]
Aug 16 2009, 20:45
yep disregard my post. if element in array does work of course.. :|

[ASA]ODEN
Aug 17 2009, 05:35
Well, I got it to work by first ensuring that the array JTD_FireTrees was not empty. Apparently it doesn't like searching empty arrays :)

So I just make the array = [1,2] and it's happy :)
Oh Blimey, Good find DM - didn't know.
*Odan goes to doublecheck his missions*