OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Kundich on 27 Apr 2005, 00:06:50
-
This may have a relatively simple solution:
I have an array containing group names with noone assigned to the group (utilized the deleteVehicle command on original unit for each group). I call a random group name(s) during one iteration of the script, and want to remove that groupname from the array (although I want to reinsert it at a later point in the script). The most important lines of code are as follows:
_group = [fia_group1, fia_group2, fia_group3, fia_group4, fia_group5, fia_group6, fia_group7]
_groupLD = random 6
_groupD = _groupLD - (_groupLD mod 1)
_groupL = (_group select _groupD)
Basically, I want to remove _groupL from _group. Later, I will add it back. As I said, I'm sure it has a simple solution, but it's really starting to hack me off.
Any ideas?
-
If you head over to the ed-depot, you should find a function,
which will do this for you ;)
If you want to know how to do it manually -> here ya go:
You will have to create a new array by copying the first one,
just that you don't add the element, which you want to remove.
Finally you replace the first array with the new one.
Or: you keep the original one for later use (like you said, you
may want to add the element later again).
~S~ CD
-
Thanks, but my problem is the element to be removed is a random element of the array during each iteration. That's what's got me confused. I do want to know how to do it manually, but the element could be any group. Does that make sense?
I must be stupid, eh? Thanks for your help, though.
Thanks,
ADM
-
...OR you can just use OFP's - command (http://www.ofpec.com/editors/comref.php?letter=num#-). From the com ref:
arrayA - arrayB
Operand types:
arrayA: Array
arrayB: Array
Type of returned value:
Array
Description:
all elements in arrayB removed from arrayA
So in your case it would be:
_group = _group - [_groupL]
-
Excellent. I was trying it:
_group = _group - _groupL
NO BRACKETS!!! I will check it out tonight. Thanks for your help.
Thanks,
ADM
-
Yeah, you have to read the com ref really carefully sometimes. It asks for two ARRAYS as input. You were trying to pass it an array and a GROUP. I've messed this one up many times before. Same goes for the array + array command.
-
@GB - you're right, array = array - [element] should be ok too,
maybe it could lead into a prob when trying to recreate the
original array with same order of elements but it should work.
@Kundich - it doesn't matter, wether you know what to remove
or not.
When building the new array, you would just have to do it
that way:
if (element to be added into new_array) not = (element to be
removed from old_array), then new_array = new_array + [element]
:note - this is not syntax version (just the theory, how to do it)
~S~ CD
-
Just to add further the the discussion. If the elements of the array are arrays themselves (for example if you have an array of positions) then you cannot remove any of the elements by using the - command
-
Just to add further the the discussion. If the elements of the array are arrays themselves (for example if you have an array of positions) then you cannot remove any of the elements by using the - command
For exactly that reason i tend to using the version i described above,
as when i've been working on my multi group control engine i've been
working with arrays consisting of other arrays. I prefer to use methods, which work for every case, but then again off course can
happen that easy solutions like General Barrons subtract element
from array become forgotten :D
~S~ CD
-
Thanks for the input, guys. It worked like a charm. Amazing how two little characters can make such a world of difference.
My next problem is somewhat related: under normal circumstances, a group is limited to twelve units, array elements 0 to 11. If the units in a group are killed, they automatically should be removed from an array, yes?
If so, is there some limit to the number of AI units that may be spawned to a single group over time?
Thanks,
ADM
-
As long as the group does not exceed 12 members at anyone time you can just keep going. Note however that it sometimes takes a little while for dead units to be removed from the group. Try doing a count groupname and see. Think about when you are leading a group and members get killed, if they are out of sight of other group memebers it can take a while before you are told they are dead. Untill the leader knows they are dead they are still in the group
-
IIRC count groupname returns the number of loons the group leader thinks are in the group. Or something. Use "alive _x " count units grpName to get the atual number.
-
True, but if you are planning on adding new members to a group which is the number that counts against the limit of 12, the number in the group or the number of living units in the group? I have not done any experimenting with this and I have always assumed the first of these is the impotant one, but I could be wrong.
-
I think - although I'm not sure - that the number of units in the group is the number the group leader thinks there are. Using an alive command crystallises the losses.
I'm not sure if count actually returns a wrong answer, but certainly a trigger based on count==0 should always be done with an alive command as well, otherwise there can be a delay of up to several minutes before the trigger fires.
-
Using an alive command crystallises the losses.
I didn't know that. Thanks.
-
Thanks so much. That's perfect.
Thanks,
ADM
-
I appreciate all the help. I think I've got it now. Thanks for all the help.
Thanks,
ADM