Home   Help Search Login Register  

Author Topic: [SOLVED] Counting query  (Read 2047 times)

0 Members and 2 Guests are viewing this topic.

Offline Zipper5

  • BIS Team
  • ****
[SOLVED] Counting query
« on: 20 Aug 2009, 17:36:57 »
I have three groups in a mission: grp1, grp2 & grp3

I am having trouble finding out a way to count the numbers in grp1 and see if it's below 6, count the numbers in grp2 and see if it also is below 6, count the numbers in grp3 and see if it's below 2, then based on those results determine if the mission can or can't continue.

The reason for this is I want to have each group evacuated if their numbers are too low to hold an airfield. So far, the method I used was a very complicated probability sum, using many loops, ifs and thens. I was wondering if anyone could give me some pointers on how they would approach such a problem? I'd greatly appreciate it.
« Last Edit: 22 Aug 2009, 19:51:51 by Zipper5 »

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: Counting query
« Reply #1 on: 20 Aug 2009, 18:28:05 »
 hi  to return number of units in a group you could try

_cnt1 =count units grp1 ;
_cnt2 =count units grp2 ;
_cnt3 =count units grp3;

 now you can ascertain whether your grp numbers are within your paramters , by checking value of _cnt1 etc ,
 then you can use the
http://community.bistudio.com/wiki/if
 or you can simply place a repeating gamelogic on map with condition
 (_cnt1 <6)and(_cnt2 <6)and(_cnt3 <2)

 and put your script or whatever in the action box.

 i think that should work its been a while since i made a mission though .
« Last Edit: 20 Aug 2009, 18:35:38 by DeanosBeano »
I love ofp

Offline Zipper5

  • BIS Team
  • ****
Re: Counting query
« Reply #2 on: 20 Aug 2009, 18:33:00 »
Yeah, I should have mentioned I've already done that. It's the structuring of how to ascertain it that is bothering me. So far, I've got this:

Code: [Select]
_cnt1 = count (units grp1);
_cnt2 = count (units grp2);
_cnt3 = count (units grp3);

if (_cnt1 < 6) then
{
if (_cnt2 < 6) then
{
if (_cnt3 < 2) then
{
execVM "fail.sqf"
};
else
{
};
};
else
{
if (_cnt3 < 2) then
{
execVM "fail.sqf"
};
else
{
};
};
};
else
{
if (_cnt2 < 6) then
{
if (_cnt3 < 2) then
{
execVM "fail.sqf"
};
else
{
};
};
else
{
if (_cnt3 < 2) then
{
};
else
{
};
};
};

But I keep getting an error about a missing ; on line 19, which I can't find the cause of. I don't even know if using that method above is the best one to use, hence why I'm asking.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Counting query
« Reply #3 on: 20 Aug 2009, 18:33:24 »
Hum?

What's wrong with simple:

Code: [Select]
if ({alive _x} count units grp1 > 6 && {alive _x} count units grp2 > 6 && {alive _x} count units grp3 > 2) then { bla bla bla};
Or wouldn't it make more sense to have a total minimum number (which in this case is 6+6+2, e.g. 14 men)? That way grp1 might have 1 survivor, grp2 10 and grp3 3, and you'd still be good to go ->

Code: [Select]
if ({alive _x} count (units grp1 + units grp2 + units grp3) < 14) then { bla bla bla};
(or the other way around if you want bla bla bla to be when there IS enough people, but you understand that.

Doesn't seem like TOO many ifs and maybes?

Wolfrug out.

"When 900 years YOU reach, look as good you will not!"

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: Counting query
« Reply #4 on: 20 Aug 2009, 18:37:03 »
Code: [Select]
Hum?

What's wrong with simple:
I am guessing what is wrong with it is that you havent posted it before he asked the question, therefre he didnt know ;)
I love ofp

Offline Zipper5

  • BIS Team
  • ****
Re: Counting query
« Reply #5 on: 20 Aug 2009, 18:39:25 »
Quote
Doesn't seem like TOO many ifs and maybes?
That's exactly why I wasn't happy with it.

To my knowledge, the < and > commands do not include the number you put after it in what it calculates. It does everything above or below that number, but not that number. So adding 6+6+2 will not give me the result I want.

But I'll give what you posted a try and see if that works better.

Edit: Logically, I actually don't think what you posted will work. Because one of the calculations may turn up false, while the other two might be true. That one you posted will only work if all 3 are satisfied, which isn't what I was looking for. But thanks for the advice anyways. :)
« Last Edit: 20 Aug 2009, 18:43:12 by Zipper5 »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Counting query
« Reply #6 on: 20 Aug 2009, 18:42:39 »
>= and <=?

Anyway, you want to use {alive _x} count units, since just count units will bring back how many units the leader of the group THINKS are alive, not the actual amount - a funny little quirk since OFP days.  :scratch:

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Zipper5

  • BIS Team
  • ****
Re: Counting query
« Reply #7 on: 20 Aug 2009, 18:47:03 »
Good point with the {alive _x} thing, I hadn't thought about that.

Looking at what I posted, can you see any reason why that is not working? It keeps giving me the error:

Error Missing ;
line 19

But I can't find that anywhere.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Counting query
« Reply #8 on: 20 Aug 2009, 19:20:46 »
Hm. I'm looking at your code, and yes, it does look a little overly complicated. However you seem to WANT it to be complicated; if I read the first part right, for instance, you're saying that IF grp1 < 6 AND grp2 < 6 AND grp3 < 2 then fail, else IF grp1 < 6 AND grp3 < 2 then fail, OR if grp2 < 6 AND grp3 < 2 then fail. In other words, complicated shiznits (apparently grp3 is more important here).

Basically, if you don't want it to be as easy as "if less than X men then fail", then you do have to use a bunch of ifs and thens and whats and whys. However, you can also use OR and AND to make it a little easier.

Code: [Select]
_cnt1 = {alive _x} count (units grp1);
_cnt2 = {alive _x} count (units grp2);
_cnt3 = {alive _x} count (units grp3);

if ((_cnt1 <= 6) && (_cnt2 <= 6) && (_cnt3 <=2))
then
{execvm "fail.sqf"}
else
{
if ((_cnt1 <= 6) && (_cnt3 <=2)) then {execvm "fail.sqf"}
};

etc etc. But as mentioned - if you're going to make it complicated, then you have to make it complicated! If, however, only grp3 is really important, then you could still just count the total number of units in grp1 and grp2, and then have a separate check to see if grp3  is <= 2?

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Deadfast

  • Members
  • *
Re: Counting query
« Reply #9 on: 20 Aug 2009, 20:26:29 »
There is no semi-column behind the if statement block if it's followed by else:

Code: [Select]
if (true) then
{
hint "bla";
}; //note the semi-column


if (true) then
{
hint "blabla";
} //no semi-column there
else
{
hint "blablabla";
}; //semi-column there again


This is how your code should look like then:
Code: [Select]
_cnt1 = count (units grp1);
_cnt2 = count (units grp2);
_cnt3 = count (units grp3);

if (_cnt1 < 6) then
{
if (_cnt2 < 6) then
{
if (_cnt3 < 2) then
{
execVM "fail.sqf"
}
else
{
};
}
else
{
if (_cnt3 < 2) then
{
execVM "fail.sqf"
}
else
{
};
};
}
else
{
if (_cnt2 < 6) then
{
if (_cnt3 < 2) then
{
execVM "fail.sqf"
}
else
{
};
}
else
{
if (_cnt3 < 2) then
{
}
else
{
};
};
};

Offline Zipper5

  • BIS Team
  • ****
Re: Counting query
« Reply #10 on: 21 Aug 2009, 00:40:07 »
Thanks very much, Deadfast. That removed the error message, now I just need to test and see if it works.

Offline Barbolani

  • Members
  • *
Re: Counting query
« Reply #11 on: 21 Aug 2009, 10:28:35 »
Excuse me ppl

This has no sense, as far as I noticed..

I mean in that code it doesent matter the number of units _cnt1 or _cnt2 has, only matters _cnt3 in order to check if they have enough units or not...

So the _cnt1 and _cnt2 If is no needed. Just make one to check if _cnt3 has less than 2 units.

Try it, if i am right, you will have the same results with just one If than with those three.

Best regards!

Offline Zipper5

  • BIS Team
  • ****
Re: Counting query
« Reply #12 on: 22 Aug 2009, 19:51:04 »
Well, I've actually got it working properly now. So problem solved I guess. Thanks for all of your help, guys! It's greatly appreciated.