Home   Help Search Login Register  

Author Topic: question about "count"  (Read 1688 times)

0 Members and 1 Guest are viewing this topic.

ido_

  • Guest
question about "count"
« 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 ?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: question about "count"
« Reply #1 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

ido_

  • Guest
Re: question about "count"
« Reply #2 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 ?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: question about "count"
« Reply #3 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.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: question about "count"
« Reply #4 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.

ido_

  • Guest
Re: question about "count"
« Reply #5 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 ?

ido_

  • Guest
Re: question about "count"
« Reply #6 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

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: question about "count"
« Reply #7 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.....


ido_

  • Guest
Re: question about "count"
« Reply #8 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

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: question about "count"
« Reply #9 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
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: question about "count"
« Reply #10 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 :)

ido_

  • Guest
Re: question about "count"
« Reply #11 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

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: question about "count"
« Reply #12 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
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: question about "count"
« Reply #13 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.