sizraide 4 Posted October 2, 2021 Hello people, I'm making a COOP mission and I have a trigger that spawns in AI in waves. Quote _spawnMarkers = ['enemySpawn_4', 'enemySpawn_5', 'enemySpawn_6']; attackingGroup_3 = createGroup [east, false]; while{true} do { _groupIndex = 0; //index _enemyGroup = 'septemberGroup' + (str _groupIndex); //add index to string _enemyGroup = createGroup [east, true]; _enemyGroup = [getMarkerPos (selectRandom _spawnMarkers), east, (configFile >> 'CfgGroups' >> 'East' >> 'CUP_O_RU' >> 'Infantry_Ratnik_Summer' >> 'InfAssault')] call BIS_fnc_spawnGroup; //spawn group using new variable group name _SADwp = _enemyGroup addWaypoint [getPos waveTrg3, 0]; _SADwp setWaypointType 'SAD'; { if(_x inArea waveTrg3 && alive _x) then {_enemyGroup reveal _x} } forEach allUnits; {attackingGroup_3 reveal _x} forEach allPlayers; {defend3 reveal _x; apc4 reveal _x;} forEach units _enemyGroup; {_x forcespeed 10; _x setSkill 0.8; _x allowFleeing 0;} forEach units _enemyGroup; _enemyGroup setBehaviour 'COMBAT'; _enemyGroup setSpeedMode 'FULL'; waitUntil { {alive _x} count units _enemyGroup < 5 }; //waits for previous group to have less than 5 units alive _groupIndex = _groupIndex + 1; //add +1 to index number for new group to be created sleep 1; }; The string is _enemyGroup where it holds septemberGroup0, septemberGroup1, septemberGroup2, etc... It creates a group every time the previous group has less than 5 units alive. So, the new group would be septemberGroup + new index at the end of the while loop. My question is if this is the correct way of converting strings to variables for group names? I could just use the same group name and spawn the same group every time the group has less than 5 units but from spectating the AI behavior they act really weird and stray away from their waypoint for some reason when the group respawns. Share this post Link to post Share on other sites
R3vo 2654 Posted October 2, 2021 If it works then it's good. I see no issue here for a mission that will not run 24/7. Share this post Link to post Share on other sites
sizraide 4 Posted October 2, 2021 30 minutes ago, R3vo said: If it works then it's good. I see no issue here for a mission that will not run 24/7. is the variable _enemyGroup a string or a variable is my concern? Share this post Link to post Share on other sites
R3vo 2654 Posted October 2, 2021 2 minutes ago, sizraide said: is the variable _enemyGroup a string or a variable is my concern? It's group. You make it a string first but then you assign a group to it. The string is kinda redundant. What I noticed is, you are potentially creating a new group every second so you need to keep track of the number of groups and either delete them if needed or make sure you are not exeeding a certain threshold. 2 Share this post Link to post Share on other sites
beno_83au 1369 Posted October 2, 2021 A variable is a container or a reference for some kind of information. _enemyGroup is a variable that contains some kind of data. The data that is held within _enemyGroup is what would be a string, or number, or object, or array, etc...... That's a pretty basic way of looking at it. But Revo is right. You're defining _enemyGroup as 'septemberGroup0' then just creating a group over the top of _enemyGroup so that _enemyGroup now just references that group. 2 Share this post Link to post Share on other sites
sizraide 4 Posted October 2, 2021 2 hours ago, beno_83au said: A variable is a container or a reference for some kind of information. _enemyGroup is a variable that contains some kind of data. The data that is held within _enemyGroup is what would be a string, or number, or object, or array, etc...... That's a pretty basic way of looking at it. But Revo is right. You're defining _enemyGroup as 'septemberGroup0' then just creating a group over the top of _enemyGroup so that _enemyGroup now just references that group. How can I create a new group to spawn after the previous group has less than 5 units living? By using new variables? Share this post Link to post Share on other sites
R3vo 2654 Posted October 2, 2021 1 hour ago, sizraide said: How can I create a new group to spawn after the previous group has less than 5 units living? By using new variables? You are already doing that. 2 Share this post Link to post Share on other sites
pierremgi 4862 Posted October 2, 2021 in other words, you can delete all lines about index and strings (for group). add : _enemyGroup deleteGroupWhenEmpty TRUE; 1 Share this post Link to post Share on other sites
opusfmspol 280 Posted October 2, 2021 Assuming you want each group to have a global variable so you can work with them outside this particular code block or outside the script, first you would declare the index before the while-do, then you would use call compile format : (not tested) _spawnMarkers = ['enemySpawn_4', 'enemySpawn_5', 'enemySpawn_6']; _groupIndex = 0; //initial index while {true} do { _enemyGroup = [getMarkerPos (selectRandom _spawnMarkers), east, (configFile >> 'CfgGroups' >> 'East' >> 'CUP_O_RU' >> 'Infantry_Ratnik_Summer' >> 'InfAssault')] call BIS_fnc_spawnGroup; // Define the group by the index# (septemberGroup0, septemberGroup1, septemberGroup2, etc.), Call Compile Format ['septemberGroup%1 = _enemyGroup',_groupIndex]; _SADwp = _enemyGroup addWaypoint [getPos waveTrg3, 0]; _SADwp setWaypointType 'SAD'; { if(_x inArea waveTrg3 && alive _x) then {_enemyGroup reveal _x} } forEach allUnits; { defend3 reveal _x; apc4 reveal _x; _x forcespeed 10; _x setSkill 0.8; _x allowFleeing 0; } forEach units _enemyGroup; _enemyGroup setBehaviour 'COMBAT'; _enemyGroup setSpeedMode 'FULL'; waitUntil {{alive _x} count units _enemyGroup < 5 }; //waits for previous group to have less than 5 units alive _groupIndex = _groupIndex + 1; //add +1 to index number for new group to be created sleep 1; }; - Format creates the string: "septemberGroup0 = _enemyGroup" - Compile converts the string to code: {septemberGroup0 = _enemyGroup} - Call runs the code; you then have the variable defined so you can work with it. - And as index increases, the strings contain "septemberGroup1", "septemberGroup2", etc. Assuming the server is running this: if clients also needed to work with those group variables, then you would use publicVariable to broadcast to all; but first format the variable to include its index. After the call compile format line, you would insert: publicVariable Format ['septemberGroup%1',_groupIndex]; 1 Share this post Link to post Share on other sites
pierremgi 4862 Posted October 2, 2021 If you absolutely want to name a group this way, make it simple: _groupIndex = 2; //example missionNameSpace setVariable ["septemberGroup"+str _groupIndex, [getMarkerPos (selectRandom _spawnMarkers), east, (configFile >> 'CfgGroups' >> 'East' >> 'CUP_O_RU' >> 'Infantry_Ratnik_Summer' >> 'InfAssault')] call BIS_fnc_spawnGroup, TRUE]; // group is created and named septemberGroup2 private _enemyGroup = missionNameSpace getVariable ("septemberGroup"+str _groupIndex); // same as septemberGroup2.... 2 Share this post Link to post Share on other sites
sizraide 4 Posted October 3, 2021 15 hours ago, pierremgi said: If you absolutely want to name a group this way, make it simple: _groupIndex = 2; //example missionNameSpace setVariable ["septemberGroup"+str _groupIndex, [getMarkerPos (selectRandom _spawnMarkers), east, (configFile >> 'CfgGroups' >> 'East' >> 'CUP_O_RU' >> 'Infantry_Ratnik_Summer' >> 'InfAssault')] call BIS_fnc_spawnGroup, TRUE]; // group is created and named septemberGroup2 private _enemyGroup = missionNameSpace getVariable ("septemberGroup"+str _groupIndex); // same as septemberGroup2.... If I want to refer to that group, I can type _enemyGroup? For example if I type _enemyGroup setSpeedMode "FULL" it will refer to septemberGroup2? Share this post Link to post Share on other sites
pierremgi 4862 Posted October 3, 2021 Yes, another way to call the group, if you follow the example. The 1st line set the variable in mission namespace, so your variable: missionNameSpace getVariable "septemberGroup2" (example above) is same as septemberGroup2 (global variable, even public as 3rd parameter is set to true). The second line is not mandatory: private _enemyGroup = missionNameSpace getVariable ("septemberGroup"+str _groupIndex); allows you to refer to _enemyGroup as another (local) variable. The only interest is this local reference is slightly faster for multiple commands, compared to global variables. Time for you to read this page. 1 Share this post Link to post Share on other sites