Home   Help Search Login Register  

Author Topic: Create new defenders in fixed positions - error in sqf  (Read 1134 times)

0 Members and 1 Guest are viewing this topic.

Offline Felonmarmer

  • Members
  • *
I have a bunch of fixed MG's named MG1...MG8, and I want to check if theirs a gunner in them or if they have been killed and if do replace them from a limited supply. I'm using an array rather than using a format ["MG%1",_var] so I can vary it with differently named objects.

The code is as follows but I get a type string expected error and a missing semicolon error and I can't fathom out where the codes wrong.

Code: [Select]
_UKNum=100;
_Location=["MG1","MG2","MG3","MG4","MG5","MG6","MG7","MG8"];
_BaseDefenders = createGroup West;
_debug=true;
while {_UKNum>0} do
{
for [{_i=0}, {_i<8}, {_i=_i+1}] do
{
if (_UKNum>1) then
{
_MGString = (_Location select _i);
_MG = call compile _MGString;
if (isNull gunner _MG) then
{
_UKNum=_UKNum-1;
if (_debug) then {hint format["Numbers : %1",_UKNum]};
_gunner= _BaseDefenders ["SoldierWB", position _MG, [], 0, "NONE"];
_gunner moveInGunner _MG;
};
};    
};
sleep 30+(random 30);
};

Can anyone point out the error(s) before my head explodes.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Create new defenders in fixed positions - error in sqf
« Reply #1 on: 01 Mar 2009, 16:50:13 »
We-eell, the most obvious thing that jumps into your face is that you've got the createUnit syntax wrong. More precisely, you forgot the actual command ;)

_gunner= _BaseDefenders createUnit ["SoldierWB", position _MG, [], 0, "NONE"];

As to the complicated for....do, I never understood the point of making it that damned complicated, but there might be something wrong there; ask someone who understands how that thing works ;)

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Felonmarmer

  • Members
  • *
Re: Create new defenders in fixed positions - error in sqf
« Reply #2 on: 01 Mar 2009, 17:02:59 »
 :-[ Doh
That fixed it, must remember to actually use the command!

Cheers

Offline Deadfast

  • Members
  • *
Re: Create new defenders in fixed positions - error in sqf
« Reply #3 on: 01 Mar 2009, 20:12:29 »
I took the liberty to rewrite the code to look a bit less complicated yet do the same thing ;)

Code: [Select]
_UKNum = 100;
_Location = ["MG1","MG2","MG3","MG4","MG5","MG6","MG7","MG8"];
_BaseDefenders = createGroup West;
_debug = true;
while {_UKNum>0} do
{
{
_MG = call compile _x;
if ( (isNull gunner _MG) && (_UKNum > 1) ) then
{
_UKNum = _UKNum-1;
if (_debug) then {hint format["Numbers : %1",_UKNum]};
_gunner = "SoldierWB" createUnit [position _MG, _BaseDefenders];
_gunner moveInGunner _MG;
};    
} forEach _Location;
sleep 30+(random 30);
};

Offline Rommel92

  • Members
  • *
Re: Create new defenders in fixed positions - error in sqf
« Reply #4 on: 01 Mar 2009, 22:36:09 »
And I merely removed a few more things. Namely a compile, and made it so theres exactly 100 re-spawns, instead of 99.   :D
Code: [Select]
_d = true;
_i = 100;
_m = [mg1, mg2, mg3, mg4, mg5, mg6, mg7, mg8];
_gr = creategroup west;
while {_i > 0} do {
{
if ( (isnull gunner _x) && (_i > 0) ) then {
_i = _i - 1;
if (_d) then {hint format ["Respawns Left : %1", _i]};
private "_g";
_g = "SoldierWB" createunit [getpos _x, _gr];
_g moveInGunner _x
}
} foreach _m;
sleep 30 + (random 30)
};

note: I also did the pain in the ass thing and re-named the variables to shorter representations.  :whistle:
« Last Edit: 01 Mar 2009, 22:41:53 by Rommel92 »