Jump to content
Sign in to follow this  
tryteyker

Getting unitname and storing it in a specific variable using foreach?

Recommended Posts

Hi,

I'm nearly complete with my boat script, just need to work out how to get the people back into the boat. What I thought of is creating an array and passing every unit into that array for later use with forEach.

How would I accomplish this?

{
boat1units = _x;
} foreach crew boat1;

is obviously not gonna work.

Any ideas?

Share this post


Link to post
Share on other sites

This should work, but is untested :

_boatCrewArray = [];
{
   _boatCrewArray = _boatCrewArray + [ _x ];
} forEach crew boat1;

Share this post


Link to post
Share on other sites

Thanks, it sorta worked. Seems like I'm more running into modeling issues that I can't seem to fix, specifically that the crew of the boat won't move into cargo positions when sitting in an attached boat. Well, more testing.

Share this post


Link to post
Share on other sites

Try this, it's a little odd but works when I instantly want one lot of units switch to another vehicles.

{moveout _x;_x moveincargo newcar;_x leaveVehicle oldcar} foreach crew oldcar;

Edited by F2k Sel

Share this post


Link to post
Share on other sites
About the first question, just name the crew array once :

boatarray = crew boat1

*Facepalm*

So simple, and yet so right..

No clue why I never figured that out :D

Share this post


Link to post
Share on other sites
*Facepalm*

So simple, and yet so right..

No clue why I never figured that out :D

Well I had this ready at first but was not sure how to properly implement it, so your suggestion worked just as fine actually.

Hey, F2k Sel, thanks for the piece of code. Is there a way to turn that around and make units move into the cargo of the boat instead? As I mentioned previously the boat is pretty much invisible and moveincargo doesn't work. The script itself returns no errors.

Also, what would be the best way to basically count all units within an array, and if one of these units isn't in the boat once an action gets executed, move that unit into the boat? The condition has to fit into an if-statement (well that's the plan anyway)

Edited by tryteyker

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  

×