Jump to content
Lineman

Variable Names for Units Spawned From Array

Recommended Posts

Trying to spawn a group of units with each unit having a variable name so I can do stuff like give each a unique loadout after spawning.

 

Everything seems to work, until the last line of the below script "removeUniform SpawnSoldier_02;". I receive an error "error removeuniform: type string, expected object".
 

Spoiler

 

SpawnSoldier_02 = "B_SOLDIER_A_F";
SpawnSoldier_03 = "fow_s_ger_heer_rifleman";

 

_unitsInGroup = [SpawnSoldier_02, SpawnSoldier_03];

 

newGroup = createGroup [west,true];
_SpawnSoldier_01 = "fow_s_ger_heer_rifleman" createUnit [_CorpSpawnPosition,newGroup,"SpawnSoldier_01 = this"];
sleep 1;

 

{
_x createUnit [_CorpSpawnPosition,newGroup,"_x = this"];
    sleep .4;
}forEach _unitsInGroup;
sleep 1;
    removeUniform SpawnSoldier_02;

 

 

Share this post


Link to post
Share on other sites

As you have defined it spawnsoldier_02 is the string of the class name,  not the created unit

  • Like 1

Share this post


Link to post
Share on other sites
Just now, Mr H. said:

As you have defined it spawnsoldier_02 is the string of the class name,  not the created unit

Thanks that helps! It was meant to be the variable of the created unit.

Share this post


Link to post
Share on other sites

Also the "_x =this" in your initial parameter won't work, it will be treated as part of the string and not as a variable

  • Like 1

Share this post


Link to post
Share on other sites
Spoiler

_SpawnSoldier_02 = "B_SOLDIER_A_F" createUnit [_CorpSpawnPosition,newGroup,"SpawnSoldier_02 = this"];
sleep .4;
_SpawnSoldier_03 = "fow_s_ger_heer_rifleman" createUnit [_CorpSpawnPosition,newGroup,"SpawnSoldier_03 = this"];
sleep .4;
_SpawnSoldier_04 = "fow_s_ger_heer_rifleman" createUnit [_CorpSpawnPosition,newGroup,"SpawnSoldier_04 = this"];
sleep.4;

 removeUniform SpawnSoldier_02;

Decided to define the variables separately rather than using an array and it works. Thanks again!

Share this post


Link to post
Share on other sites

@Lineman,

{
    call (compile (format (["%1 = '%2' createUnit [_CorpSpawnPosition, newGroup];"] + _x)));
} forEach [
    ["SpawnSoldier_02", "B_SOLDIER_A_F"],
    ["SpawnSoldier_03", "fow_s_ger_heer_rifleman"]
];

sleep 1;

removeUniform SpawnSoldier_02;
  • Like 2

Share this post


Link to post
Share on other sites
On 27.8.2018 at 9:44 PM, Schatten said:

call (compile (format (["%1 = '%2' createUnit [_CorpSpawnPosition, newGroup];"] + _x)));

call compile format combination is almost always stupid.

 

missionNamespace setVariable [_x select 0, (_x select 1) createUnit [_CorpSpawnPosition, newGroup]];

 

  • Like 1

Share this post


Link to post
Share on other sites
15 minutes ago, Dedmen said:

call compile format combination is almost always stupid.

Really? Proofs?

Share this post


Link to post
Share on other sites
3 hours ago, Schatten said:

Really? Proofs?

 

Put this into debug console and benchmark it

missionNamespace setVariable ["abc", 123];

vs

call compile format ["%1 = %2", "abc", 123];

 

  • Like 2

Share this post


Link to post
Share on other sites

Just for the curious:

missionNamespace setVariable ["abc", 123];//0.001ms
call compile format ["%1 = %2", "abc", 123];//0.0025ms

Performance loss is kinda given.

Some other reason for not using call compile format, in terms of sending code via network, though a bit unrelated to this topic.

 

Cheers

Share this post


Link to post
Share on other sites
5 hours ago, Dedmen said:

call compile format combination is almost always stupid.

 


missionNamespace setVariable [_x select 0, (_x select 1) createUnit [_CorpSpawnPosition, newGroup]];

 

Didn't know! :O

Quote

It is magical

EKDM994.jpg

JXYgEMO.jpg

 

Share this post


Link to post
Share on other sites

Not sure lol.

i7 8700k

1080 Ti

32 GB DDR4

etc

 

Share this post


Link to post
Share on other sites

Woo! Got you beat by a whole five ten-thousandths of a second on the call compile format, Haz! Yeehaw!
 

Ba2BQdT.jpg?1

Edited by Harzach
fixed for Ded
  • Like 1

Share this post


Link to post
Share on other sites

People need to learn how to make non-fullscreen screenshots that don't show 80% useless empty space :D

Also no need to argue about the perf. call compile format is just stupid. PERIOD *slams fists on table*. Thanks for watching. Now to the news with Karen Bablewitz.

  • Haha 3

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×