Jump to content
Sign in to follow this  
630R93

count enemy problem

Recommended Posts

Hi guys, I have problem with counting alive enemies, I use this:

_Enemy = [npc1, npc2, npc3, npc4, npc5];

_alive = {alive _Enemy} count allUnits;

when I checked it by

hint format["%1",_alive] it displays "any", not a number as should be.

While I was writting this I find out that it might be by calling script by exec instead of execVM, until now I used only exec.

How do I use execVM correctly? Now it doesn´t even display "any".

And don´t you know what might be wrong with that counting?

I´ve spended few hours on this and still I can´t figure it out. I would appreciate any help.

Share this post


Link to post
Share on other sites

execVM is used to call sqf files, while exec is used for sqs files. Thats the difference.

And for your count, you can use this:

_enemy = […];

_aliveEnemy = {alive _x} count _enemy;

Share this post


Link to post
Share on other sites

For the hint try

hint format["%1", (str _alive)] 

The str converts the number to a word first. I'm not sure why "format" doesn't seem to do this.

Share this post


Link to post
Share on other sites
For the hint try

hint format["%1", (str _alive)] 

The str converts the number to a word first. I'm not sure why "format" doesn't seem to do this.

Incorrect. You dont need str if are using format. It will take any value and convert it to string by default. OP's use of format is right on the money.

Share this post


Link to post
Share on other sites
Incorrect. You dont need str if are using format.

You are correct! :)

I had this issue a while back and thought I had corrected it by adding "str"... I assume its something to do with the SQF variables being weakly typed although I can't replicate the "any" response now.

Share this post


Link to post
Share on other sites
You are correct! :)

I had this issue a while back and thought I had corrected it by adding "str"... I assume its something to do with the SQF variables being weakly typed although I can't replicate the "any" response now.

Format will show you nil variables too where as str won't. Basically it converts anything you throw at it into string. I suspect though it is slower than str. 'any' is a legit SQF value for variable with no value.

Share this post


Link to post
Share on other sites
execVM is used to call sqf files, while exec is used for sqs files. Thats the difference.

And for your count, you can use this:

_enemy = […];

_aliveEnemy = {alive _x} count _enemy;

Thank you very much! it works now, but what does that {alive _x}, if _x isn´t declared before? This command creates it? I thought I have to create all variables before any use. And Am I using right way execVM like this: null = [] execVM "Safehouse_Part3.sqf" ?

And thank you this helps me a lot!:)

---------- Post added at 14:47 ---------- Previous post was at 14:45 ----------

You are correct! :)

I had this issue a while back and thought I had corrected it by adding "str"... I assume its something to do with the SQF variables being weakly typed although I can't replicate the "any" response now.

Try to call it by exec instead of execVM to replicate "any" that "works" for me.

Share this post


Link to post
Share on other sites
what does that {alive _x}, if _x isn´t declared before

"_x" is a variable that is populated by Arma inside a loop. It is local to that loop meaning it can't be used outside the loop.

Basically the count function goes over everything in the "_enemy" list. For each item in the list it saves that item to _x then does whatever you tell it to inside the {} brackets. The wiki puts it this way:

The variable _x will contain the currently tested element.

http://community.bistudio.com/wiki/count

Share this post


Link to post
Share on other sites
"_x" is a variable that is populated by Arma inside a loop. It is local to that loop meaning it can't be used outside the loop.

Basically the count function goes over everything in the "_enemy" list. For each item in the list it saves that item to _x then does whatever you tell it to inside the {} brackets. The wiki puts it this way:

http://community.bistudio.com/wiki/count

I see :) I didn´t notice that on wiki. Thanks a lot, I´m glad that I understand it all now, how it works. Thanks for your help:)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×