OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: twisted on 30 Mar 2009, 00:29:31
-
hi. i am trying to combine 2 scripts to get automatic management of ai. one script 'recruits' the group in a global array. the other script then references this global array to tell the units what to do in a cohesive manner. well, at least thats the idea.
problem is my limited knowledge and abilities in sqf coding. my recruit.sqf isn't properly naming the group, which means in the other script it only sees the array reference as a string not an actual group. // recruit function. gives unique name and adds team to index
if !(isserver) exitwith {};
if (isNil("TW_INIT")) then { //first time run?
TW_INIT=1;
recruits = 0;
allopfor = [];
totalmen = 0;
};
recruits = recruits + 1;//keep track of total groups recruited
private ["_opfor","_totalopfor","_grpindex"];
_opfor = _this select 0;
// give this group a unique index
_grpindex = format ["%1",recruits]; //learnt from kronskys great ups script.
_grpname = format ["%1_%2", (side _opfor),_grpindex]; // diito
player sidechat format ["grpindex and grpname and total opfor = %1 %2 %3", _grpindex, _grpname, count allopfor];
totalmen = totalmen + (count units _opfor); //keep track of number of units
allopfor = allopfor + [[_grpname]]; //create list of all opfor groups
_totalopfor = count allopfor; //keep track of number og groups
please help. in the other script a call of [_tempgroup, _waypoint] call _runto;
which links to...
_runto =
{
private ["_reccegroup","_waypoint"];
_reccegroup = _this select 0;
_waypoint = _this select 1;
{_x doMove _waypoint; } forEach units _reccegroup;
};
returns a error something like group expect but type is string.
advise greatly appreciated
-
The essential problem is that you are storing names of groups, but those names do not associate, in any way, with the groups themselves. However, even giving them names is unnecessary, since you can always refer to them via select or in a forEach loop, since you are storing them in an array:
_group = TW_allopfor select 5; // Get a reference to the 6th group in the list.
{ ... do stuff to each group ... } forEach TW_allopfor;
You are overcomplicating things; I feel you could remove most of the code:
if !(isserver) exitwith {};
if (isNil("TW_allopfor")) then { //first time run?
TW_allopfor = [];
TW_totalmen = 0;
};
private ["_opfor"];
_opfor = _this select 0;
TW_allopfor set [count TW_allopfor, _opfor]; // push onto list of groups
TW_totalmen = TW_totalmen + (count units _opfor); //keep track of number of units
player sidechat format ["Added: %1, total groups: %2, total men: %3", _opfor, count TW_allopfor, TW_totalmen];
At any time, you can find out how many groups there are with count TW_allopfor, so there is not any need to keep separate counters for that.
I notice that you've used a tag on TW_INIT, but not on your other global variables. The point of the tag is that it is prepended to all your global variables, not just some of them (I've made the alteration above). Note that a 2-letter tag is not a valid OFPEC tag, which should be 3-5 letters long. Usually, if you are the mission-maker, tags are not compulsory; It only really matters if you are publishing your script to be used in other missions, where variable names could be being used for something else.
TW_allopfor now contains a list of all opfor groups ([group1, group2, ...]). You actually had a list of lists originally ([[group1], [group2], ...]) which was unnecessary complexity. You may need to simplify some other code to allow this to continue working, though, but this way is much clearer.
runto seems fine (~cough~ TW_runto). The problem was that you were just passing it a string name for a group, rather than the group itself.
-
thanks a lot. simpler is always better.
goes to show the difference knowing what you are doing makes. :)
this helps, as all i have learnt about SQF and scripting is from the feedback on this board and my own interpretations of others people sqf scripts.
i will try what you have shown.
and i was just trying out tags - if i ever get this in a releasable form i will use proper ofpec tag guidelines.