Jump to content
Sign in to follow this  
Nielsen

SetVehicleInit not working in my forEach array.

Recommended Posts

I'm spawning some units and I want to set their init.

Normally I would do this with the "type createUnit unitInfo" command, and set the init there. But I need to spawn them in a 100m radius og the player. I only know how to do this with the "group createUnit []" command. And this command does (AFAIK) not allow to set the vehicle init.

I then try to set the vehicle init afterwards with the setVehicleInit command:

{ _x setVehicleInit "this addEventHandler ["killed", {killedno = killedno + 1; PublicVariable "killedno";}];"; } forEach units _grp;

I spawn the group with this code:

_grp = createGroup east;sleep 0.05;
_unit = _grp createUnit ["TK_INS_Soldier_HAT_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit] join _grp;
_unit2 = _grp createUnit ["TK_CIV_Takistani03_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit2] join _grp;
_unit3 = _grp createUnit ["TK_CIV_Takistani04_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit3] join _grp;
_unit4 = _grp createUnit ["TK_CIV_Takistani02_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit4] join _grp;
_unit5 = _grp createUnit ["TK_CIV_Takistani05_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit5] join _grp;
_unit6 = _grp createUnit ["TK_CIV_Takistani01_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit6] join _grp;
_unit7 = _grp createUnit ["TK_CIV_Takistani06_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit7] join _grp;
_unit8 = _grp createUnit ["TK_CIV_Worker02_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit8] join _grp;
_unit9 = _grp createUnit ["TK_CIV_Worker01_EP1", getPos player1, [], 100, "FORM"];sleep 0.05;
[_unit9] join _grp;

I get a scripterror in line 42, the line of the setVehicleInit. It says i'm missing an ;. But I can not see that I do. However I have tried all variations of ; in the sentence that I can think of, and it does not work.

Can anybody tell me what I have missed?

Thanks in advance.

Share this post


Link to post
Share on other sites

{ _x setVehicleInit "this addEventHandler ["killed", {killedno = killedno + 1; PublicVariable "killedno";}];"; } forEach units _grp;

"this: here you start the string with the quotes. }];" here you wanna end it. But Arma thinks you end the string here: ler ["kil and that you start a new string here led", {. If you want " in a string you need to write them twice: "". So you should write this:

{ _x setVehicleInit "this addEventHandler [""killed"", {killedno = killedno + 1; PublicVariable "killedno";}];"; } forEach units _grp;

Share this post


Link to post
Share on other sites

AHA! So that's it.

I remember seeing the use of double "" before, but I never knew when to use it.

It's funny how problemsolving little specifik issues, helps you understand scripting in general much better. Thanks man :rthumb:

BTW: If what you say is allways true, then shouldnt the code really be:

{ _x setVehicleInit "this addEventHandler [""killed"", {killedno = killedno + 1; PublicVariable [color="Red"]"[/color]"killedno"[color="Red"]"[/color];}];"; } forEach units _grp; 

:)

Edited by Nielsen
Addition

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  

×