Jump to content

Recommended Posts

Hello,

I need object names to be defined inside an array so instead of writting each one of them, I can just write the array name.

Now, I know that an array is being defined like this:

objects=["obj1", "obj2", "obj3", "obj4"]:

But I dont know how to use this array. Or where to put the array so the game will recognize this as an array.

Share this post


Link to post
Share on other sites

Hello,

I need object names to be defined inside an array so instead of writting each one of them, I can just write the array name.

Now, I know that an array is being defined like this:

objects=["obj1", "obj2", "obj3", "obj4"]:

But I dont know how to use this array. Or where to put the array so the game will recognize this as an array.

 

As I said on steam it depends on ur problem. It would be a better help if u tell us what exactly u try to do.

Share this post


Link to post
Share on other sites

Assuming u have an array named _objects with a unspecified number of objects u can do the following things:

// count number of elements and decrease by one to fit the arrays index
_objcount = (count _objects) - 1;
 
//counting the index manually by a loop
while{_objcount > -1} do
{
 (_object select _objcount)  setPos [0,0,0];
 _objcount = objcount-1;
};

or this:

// automatic looping with forEach where magic variable _x represents the 
current _object
{
 _x setPos [0,0,0];
} forEach _object;
 
 

Share this post


Link to post
Share on other sites

As I said on steam it depends on ur problem. It would be a better help if u tell us what exactly u try to do.

I have a trigger and in the activation of it I'm using say3d, looks like this:

lp1 say3D "alarm";
lp2 say3D "alarm";
lp3 say3D "alarm";
lp4 say3D "alarm";
lp5 say3D "alarm";
lp6 say3D "alarm";

It works but because it's being executed one after another, lp2-6 is being played in a delay.

So I thought if I define them in an array they will play all at once.

Share this post


Link to post
Share on other sites

I have a trigger and in the activation of it I'm using say3d, looks like this:

lp1 say3D "alarm";
lp2 say3D "alarm";
lp3 say3D "alarm";
lp4 say3D "alarm";
lp5 say3D "alarm";
lp6 say3D "alarm";

It works but because it's being executed one after another, lp2-6 is being played in a delay.

So I thought if I define them in an array they will play all at once.

 

this is not an issue of not using an array. using an array will not solve the problem. thats the reason why I told u to descibe ur specific problems at the forum.

I think the problem can be solved with the usage of e.g. spawn.

but i have to work now... cant explain. maybe some other guy does it or has another solution for u.

If not ill answer later.

Share this post


Link to post
Share on other sites


{

  _x say3D "alarm";

  false;

} count [lp1,lp2,lp3,lp4,lp5,lp6]

Share this post


Link to post
Share on other sites
{
  _x say3D "alarm";
  false;
} count [lp1,lp2,lp3,lp4,lp5,lp6]

Is it possible doing the same with this code line?

{
nul = [_x,"alarm"] call fn_netSay3D;
false;
} count [lp1,lp2,lp3,lp4,lp5,lp6]

Share this post


Link to post
Share on other sites

What's fn_netSay3D and what does it do?

Share this post


Link to post
Share on other sites

Seems like this function executes say3D globally, however if you use my code in a trigger it will be executed globally anyway.

Share this post


Link to post
Share on other sites
{
  _x say3D "alarm";
  false;
} count [lp1,lp2,lp3,lp4,lp5,lp6]

 

Why would you use count instead of forEach?

{
  _x say3D "alarm";
} forEach [lp1, lp2, lp3, lp4, lp5, lp6];
  • Like 1

Share this post


Link to post
Share on other sites

I find it difficult to believe since the handling of the code's return value will likely outweigh the benefit gained by not having the _forEachIndex variable. Besides, for a small array this is just premature optimization.

Share this post


Link to post
Share on other sites

Yea, I wasn't saying that your're not right, just the reason why some people use count over forEach, and in this instance, the return from count isn't necessary and _forEachIndex is also not necessary so truly it doesn't matter either way, and yea the data sample is small enough to not exactly matter.

Share this post


Link to post
Share on other sites

Count : 0.133654 ms

Foreach: 0.252398 ms

 

Count is in this case  47,04634%  faster

Share this post


Link to post
Share on other sites

Count : 0.133654 ms

Foreach: 0.252398 ms

 

Count is in this case  47,04634%  faster

Can confirm. Interesting.

 

 

The only reason (i could imagine) is: It counts the Array before executing the forEach.

 

EDIT: Ah, didn't noticed the Link posted by jshock above.

Share this post


Link to post
Share on other sites

The end user won't notice the difference, but in general use count instead of foreach for simple tasks, and foreach for more complex (where you're likely to require foreachindex variable. new and exciting is the apply command, can replace count in many cases.

Share this post


Link to post
Share on other sites

Count : 0.133654 ms

Foreach: 0.252398 ms

 

Count is in this case  47,04634%  faster

 

Interesting, what exactly were you testing this with?

Share this post


Link to post
Share on other sites

With the brand new diag_codePerformance command (debug console, dev branch)

Share this post


Link to post
Share on other sites

{systemchat _x;}count ["1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"];
{systemchat _x;}forEach ["1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"];
try this @deadfast

(Console -> press the "speedometer"-button next to "Server Exec")

arma3debugthumbnail.jpg

Share this post


Link to post
Share on other sites
{systemchat _x;}count ["1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"];

Why does that work without boolean but say3D doesn't? Both commands return nothing?

 

 

condition: Code that must return true for the tested element to be counted. The variable _x will contain the currently tested element.

 

From the wiki

Share this post


Link to post
Share on other sites

With the brand new diag_codePerformance command (debug console, dev branch)

 

I meant which data :).

Share this post


Link to post
Share on other sites
{systemchat _x;}count ["1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"];
Why does that work without boolean but say3D doesn't? Both commands return nothing?

 

 

From the wiki

 

Lets take "example 2"

_cnt = {_x == 4} count [1,4,4,5,5,5];
systemchat str _cnt;

systemchat shows "2"

Reason: 2x "true" (_x is a 4) / 2x CurrentCount(starting with 0) + 1 

while:

 

_cnt = {systemchat str _x} count [1,4,4,4,5,5,5];

only activates/executes the "systemchat str _x" part.

So no True/false is given. That means: "systemchat str _cnt" would be "0"

another example:

 

_cnt = {_x} count [true,true,true,true];
systemchat str _cnt;

would show "4"

Reason: 4x "true" / 4x CurrentCount(starting with 0) + 1

 

 

 

Say3D:

 

erm... looks like say3D stacks sounds and executes the following sound, when the current one is done properly.

 

[] spawn {player say3D "Alarm";}; -> 1x Sound

[] spawn {player say3D "Alarm"; player say3D "Alarm"; }; -> 2x Sound after another
[] spawn {player say3D "Alarm"; sleep 0.5; player say3D "Alarm"; }; -> 2x Sound after another (exactly as above)
[] spawn {player say3D "Alarm"; sleep 0.5; player say3D "Alarm"; sleep 0.5; player say3D "Alarm"; }; -> 3x Sound after another (exactly as above)
[] spawn {player say3D "Alarm"; player say3D "Alarm"; player say3D "Alarm"; }; -> 3x Sound after another (exactly as above)
 
 
+
{player say3D _x} count ["Alarm","AlarmCar","Alarm"];

Executes the sounds after another.

  • Like 1

Share this post


Link to post
Share on other sites

Simple way to put it, within the braces ({ }), any and all code there is executed, however, only when there is a true value returned at some point will count increment itself for its return value.

  • Like 1

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

×