Jump to content
Sign in to follow this  
Guest

What is wrong with this code?

Recommended Posts

Guest

if (side player == blufor) then {

if(side _x == alive) then

{

if (side _x == CIVILIAN) then {_x addAction ["Detain", "detain.sqf"]};

} forEach allUnits;

};

There's something wrong with the if(side _x == alive then bla bla bla) part, But what? please help. :confused:

Share this post


Link to post
Share on other sites

There's is no "alive" side. It's a command that that checks of an object is alive. The format is: alive object, not object == alive :)

I also think you're missing curly braces

Share this post


Link to post
Share on other sites
Guest
There's is no "alive" side. It's a command that that checks of an object is alive. The format is: alive object, not object == alive :)

I also think you're missing curly braces

I don't really understand, if (alive civillian) bla bla bla? :confused:

Share this post


Link to post
Share on other sites
Guest
Hi, try this

if (side player == blufor) then {
  {
     if (alive _x and side _x == CIVILIAN) then {
           _x addAction ["Detain", "detain.sqf"];
     };
  } forEach allUnits;
};

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

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

That works! Thankyou very much :)

---------- Post added at 11:06 ---------- Previous post was at 11:05 ----------

That works! Thankyou very much :)

But i still have a qeustion wth is _X???

Share this post


Link to post
Share on other sites
Guest
This page explains the available data types:

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

Well, You're fast :)

---------- Post added at 11:23 ---------- Previous post was at 11:08 ----------

Well, You're fast :)

Well, I don't see any explanation about the _x...

Share this post


Link to post
Share on other sites

You have created a For .... next loop with the forEach allUnits; piece of code

This makes it step through the code for every single unit on the map - as it steps through the code the _x is the LOCAL variable currently being worked on

In this case it is a specific unit, incremented as you go though all the units - an engine variable

Edited by Kamakazi
spelling and clarity I hope

Share this post


Link to post
Share on other sites
Guest
You have created a For .... next loop with the forEach allUnits; piece of code

This makes it step through the code for every single unit on the map - as it steps through the code the _x is the LOCAL variable currently being worked on

In this case it is a specific unit, incremented as you go though all the units - an engine variable

I'm still a bit confused, the _x just makes it go through a specific unit in this case? Uhmm, Sorry for being so stupid <-<

Share this post


Link to post
Share on other sites

The _x is just the placeholder

every time you loop - its a different unit

if (side player == blufor) then {
  {
     if (alive _x and side _x == CIVILIAN) then {
           _x addAction ["Detain", "detain.sqf"];
     };
  } forEach allUnits;
};

sort of the rough logic as I read the code

Take a unit - call it _x

Is it bluefor

is it alive AND a civilian

then Addaction

NEXT unit

finnish when you have checked EVERY unit on the map

The _x increments every time you loop through - its a pointer to the current unit being checked.

The _x is LOCAL to your FOR ... NEXT

It is a system/ engine variable used to just keep track of where it is in the process

Hope that makes sense. There are some good examples in the forums written by better coders than me - a couple of them were linked earlier.

Do some searching for more examples of this used in similar pieces of code

Share this post


Link to post
Share on other sites

It briefly explained here http://community.bistudio.com/wiki/forEach

Basically _x refers to the current element in the array as the loop iterates.

It's the same thing as writing it like this:

array = ["a","b","c"];
for "_i" from 0 to (count array)-1 do {
 _element = array select _i;
 // count array returns 3, arrays start at index 0,hence we have to do -1 in the expression.
 //_element will refer to each element in the loop as we iterate
};

Posted from phone hope it looks ok :)

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  

×