Advertisement

Author Topic: Array and name questions  (Read 316 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Array and name questions
« on: 11 Feb 2009, 18:33:59 »
Hi... Ehh me again.

Is there a way to name units through a script and dynamically change the name depending of the order you name the units in... something like this:

First unit is named soldier + 1 result is soldier1
Next unit is named soldier + 2 result is soldier2 etc.

What I'm looking for is a way to have a basic name (i.e soldier) and then attach a string or number to it by the script so that they will automatically be called soldier1, soldier2 etc depending on the order they are named by the script. Hope that explained my problem.


Another thing that would help me achieve my goal was if you could get any members of an array to be detected in a trigger. Just like you can put: badguy in thislist (detected by OPFOR) or any groupmember (detected by OPFOR) I wonder if you can put any separate units (even from different sides) in the same array and then check if any of them they are i.e detected by OPFOR.

Cheers

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Array and name questions
« Reply #1 on: 11 Feb 2009, 20:14:14 »
Code: [Select]
for [{_i=0},{_i<10},{_i=_i + 1}] do
{
   _unit = createUnit blah blah blah blah
   call compile format ["soldier%1 = _unit", _i];
};

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Array and name questions
« Reply #2 on: 11 Feb 2009, 22:13:24 »
Sorry for not being clear enough,

What I meant was renaming units that already existed.

For a "detecting friendly dead body" script I want to try a solution where a unit with eventhandler "killed" creates a trigger that has the unit itself (unitName in thislist) detected by friendly side after its death.
To avoid having to name all potential "dead guys" beforehand, I want the script to name the units dynamically in the eventhandler.

I'll try the format thing and see what I can do.

Thanks yet again.

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Array and name questions
« Reply #3 on: 11 Feb 2009, 22:22:40 »
well, lets say you have an array of existing units:
Code: [Select]
_i = 0;
{
   _unit = _x;
   call compile format ["soldier%1 = _unit", _i];
   _x SetVehicleVarName format ["soldier%1", _i];
   call compile format ["publicVariable ""soldier%1""",_i];
   _i = _i + 1;
} forEach _my_array_of_already_existing_units;

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Array and name questions
« Reply #4 on: 11 Feb 2009, 23:38:05 »
Thanks, just updated the body detection script post.

http://www.ofpec.com/forum/index.php?topic=32963.msg227026#msg227026
« Last Edit: 11 Feb 2009, 23:53:27 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Array and name questions
« Reply #5 on: 12 Feb 2009, 10:18:52 »
Sorry guys, but you are falling into the standard trap of using unnecessary dynamic code when an array already does what you want without the pain!

If you already have an array of units, then they are numbered by the indices they occupy in the array, so you can access them easily without having to mess around with dynamic code at all (dynamic code is more complex and harder to debug).

Then, when you want to access the soldier, instead of using:
Code: [Select]
_frog = call compile format ["soldier%1", _i];
You can simply use:
Code: [Select]
_frog = soldiers select _i;
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Array and name questions
« Reply #6 on: 12 Feb 2009, 11:39:14 »
Beware, this has nothing to do with renaming units, just elementary selection from an array. Which means that if you want to affect an unit from a different machine than where the array was built, then you need to publish the array or create the array in the other machine too. If not, then you can just rename the units as indicated above and refer to them by the name from any machine. It all depends on the mission requirements.