OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: ido_ on 27 Sep 2006, 00:14:03

Title: question about "count"
Post by: ido_ on 27 Sep 2006, 00:14:03
I have made the followin condition:

?("_x in herc2" count units u1Grp)==(count units u1Grp): herc2ready=TRUE

I have this for each of my groups, the mission should end when all the groups are inside the aircrafts.
what will happen if a whole group will be dead will it be true or false ?
Title: Re: question about "count"
Post by: Mandoble on 27 Sep 2006, 00:28:03
What about:
Code: [Select]
?(("_x in herc2" count units u1Grp)==("alive _x" count units u1Grp))&&(vehilce leader u1Grp == herc2): herc2ready=TRUE
Title: Re: question about "count"
Post by: ido_ on 27 Sep 2006, 01:02:42
The array made of the group with "units u1Grp" has dead units inside ?
isn't it updating all the time with the current members of the group and returns grpNull when no one is left alive ?

and why did you put this part?:
Code: [Select]
&&(vehilce leader u1Grp == herc2)
shouldn't "vehicle" accept OBJECT and not GROUP ?
Title: Re: question about "count"
Post by: Mandoble on 27 Sep 2006, 02:07:50
As far as I remember, yes, group unit array updates periodically, but not a the very same time as this group has a casuality.
About the leader, every group has a leader (if someone is alive), your initial condition would be true with all the group dead, 0 == 0, but not if the leader is inside the herc.
Title: Re: question about "count"
Post by: THobson on 27 Sep 2006, 04:03:03
Rather than doing 2 counts you might find it easier to read an understand if you only count the number of living units that are not in the chopper and take action when that number is < 1, as follows:

Code: [Select]
herc2ready = ({(alive _x) and not (_x in herc2)} count units u1Grp < 1)
It is surprising how often counting the opposite of what you want results in a simpler solution.
Title: Re: question about "count"
Post by: ido_ on 27 Sep 2006, 11:05:23
thanx THobson, it is much simpler :), but still I didn't get an answear to my question...
my question is, what will happen if the whole group is dead, "count units group" equals to 0 ?
Title: Re: question about "count"
Post by: ido_ on 27 Sep 2006, 12:12:38
nevermind I figured that one myself by shooting civilians boarding a plane  >:D
anyways I have one more problem the condition on herc2 works great, but I have 4 hercs and each of the conditions has to be true so the mission will end.

I've made an array: _check=[_herc1ready,_herc2ready,_herc3ready,_herc4ready]

and then after checking if everyone is aboard I have this:

?(("_x" count _check) == 4) : goto "win"

but it doesn't seem to work, I've tried to look what actually comes out of : "_x" count _check , and it is 0 all the time, even is the all the values in _check are true.
I've also tried:  "_x==true" , but I got an error message
Title: Re: question about "count"
Post by: bedges on 27 Sep 2006, 12:16:06
try modifying to

Code: [Select]
?(("canmove _x" count _check) == 4) : goto "win"
i'm assuming the hercs are vehicles...  :blink:

failing that, this will work -

Code: [Select]
_i = 0
_tot = 0

#checkloop

_which_herc = _check select _i
?(canmove _which_herc):_tot = _tot + 1
_i = _i + 1
?not (_i== (count _check)):goto "checkloop"

?(_tot==4):goto "win"

hint "one of the hercs is unable to move..."
exit

#win.....

Title: Re: question about "count"
Post by: ido_ on 27 Sep 2006, 12:20:53
_herc#ready is boolean set to true when a certian group boarded herc#. I have 4 c130 and 5 groups that should board them to end the mission.
I could work around this and do: ?(_herc1ready&&_herc2ready&&_herc3ready&&_herc4ready) : goto "win"
but I'm trying to understand the "count" command and why I get 0 in the origional expression
Title: Re: question about "count"
Post by: Chris Death on 27 Sep 2006, 12:23:54
First off you got a mistake when creating your array - a comma too much at the end.

Code: [Select]
_check=[_herc1ready,_herc2ready,_herc3ready,_herc4ready,]
which should rather look like:

_check=[_herc1ready,_herc2ready,_herc3ready,_herc4ready]


But you don't store the variablename in the array but the status of the booleans.

Your array looks in real like this:

_check=[false,false,false,false]

Now if you set _herc1ready to true, the array will not become updated by that.

Also it doesn't really make sense to use an array in this case - you just use a tiny little bit
more of resources than required.

Better way is to use one numeric variable (a counter).

_counter = 0

And everytime one of your four herc's is done you increase the counter by one: _counter = _counter + 1

Once _counter reaches 4 everything's done.  ;)

~S~ C
Title: Re: question about "count"
Post by: bedges on 27 Sep 2006, 12:24:45
ah right. well in that case

Code: [Select]
? (_herc1ready and _herc2ready and _herc3ready and _herc4ready):goto "win"
simple as that :)
Title: Re: question about "count"
Post by: ido_ on 27 Sep 2006, 12:29:36
Ok Chris,

well I donno what I was thinking  :banghead:
I'll go with the 4 conditions in the if :P
Title: Re: question about "count"
Post by: Chris Death on 27 Sep 2006, 12:36:36
OK, but what i tried to tell you is:

You are using 4 variables where 1 will do the same job.
That's four time more resources than needed.

In case of more complex missions things like this will return
in lag.  ;)

You should try to save performance wherever and whenever you can.
The engine will be thankful for that and conditions will match more
often precise than when wasting resources.

~S~ CD
Title: Re: question about "count"
Post by: Mandoble on 27 Sep 2006, 18:05:37
but still I didn't get an answear to my question...
my question is, what will happen if the whole group is dead, "count units group" equals to 0 ?

just a coment. Dead units will keep inside its group as long as the group leader is not aware these units are dead. For example, you have a group of 12, 3 die inside a tank out of your visual range. You, as group leader, still have a group of 12 units. If you issue a request status to these 3 units, in few seconds you will have the confirmation of their death, and they'll be removed of your group.