Jump to content
Sign in to follow this  
mikey74

Trying to pull information from an array?

Your scripting knowledge  

6 members have voted

  1. 1. Your scripting knowledge

    • Expert
      0
    • Advanced
      1
    • Novice
      5


Recommended Posts

Please post below if you have interest in this thread, or suggestions. :)

I hope this hasnt been asked. Ive looked on several sites found similer things but nothing so far has answered what I need to know. This is my small script so far

Wrong way below:

_array = (_this select 0);
_allgroups = allGroups;
_alive = count allGroups;
_egroups = [];
_egrp = [];

for "_x" from 0 to _alive - 1 do {
_unit = _allgroups select _x;
_leader = leader _unit;
_side = side _unit;
_egroups = if ( _side == East) then {[_unit]};
_egrp = _egrp + _egroups;
};
hint format ["%1",_egrp];
sleep 3;

I call this up in the init with this

MTscript = compile preprocessFileLineNumbers "config.sqf";
_attack = [AllUnits] spawn MTscript;

What I want to do is pull out east,west, and most likely Independent groups out of an obviously allunits command, and separate each one by side. If I put hint format ["%1",_egrp]; inside the loop it seems to work fantastic, but if I take hint format ["%1",_egrp]; out of the loop it pops up just ARRAY, but not the units I'm trying to pull out. I've been pondering, searching forums, looking at others scripts but cant seem to figure out a way to do this. I've also tried a foreach loop on this, but failed miserably. lol Anybody have any suggestions?

The whole premise of this is to make AI talk to each other better group to group. I want to incorporate artillery calls, UAV usage, and coordinated attacks by and from AI. Obviously still have a long way to go. This is just the beginning of what I want to do, but I hit walls. My scripting knowledge is slightly above newbie, but way below expert. lol Anyways thanks in advance for any help and or interests.

updated with this works like a charm thanks to KevsnoTrev!!!! Sometimes another set of eyes can point out the tree you are missing in the whole forest!!! If you are learning I edited below so you can see the right way. lol

Working way:

_array = (_this select 0);
_allgroups = allGroups;
_alive = count allGroups;
_egroups = [];
_egrp = [];

for "_x" from 0 to _alive - 1 do {
_unit = _allgroups select _x;
_leader = leader _unit;
_side = side _unit;
_egroups = if ( _side == East) then {_unit};
_egrp = _egrp + [_egroups];
};
hint format ["%1",_egrp];
sleep 3;

Best way thus far:

_array = (_this select 0); 
_allgroups = allGroups; 
_alive = count allGroups; 
_egrp = [];_wgrp = [];_igrp = []; 

for "_x" from 0 to _alive - 1 do { 
_unit = _allgroups select _x; 
_side = side _unit;  
if ( _side == East) then {_egrp = _egrp + [_unit]}; 
if ( _side == West) then {_wgrp = _wgrp + [_unit]}; 
if ( _side == independent) then {_igrp = _igrp + [_unit]}; 
}; 
hint format ["East: %1\nWest: %2\nInde: %3",_egrp,_wgrp,_igrp]; 
sleep 3;

Edited by Mikey74

Share this post


Link to post
Share on other sites

to make an array from a selection like this try

[color=#333333]_egrp = _egrp + [_egroups]

[/color]

Share this post


Link to post
Share on other sites

yup Ive don that. ;) lol Thats how I ended up with [] around _unit in my code. It basically seems to do same thing. lol thanks for your quick response.

P.S. hahahahahah ignor that!!! It worked. I tried it again but how I have it written now not like before. lol Must be somethingelse I did wrong on my 1st try.... THANKS ALOT!!!!!!!!!!!!!!!!!

Share this post


Link to post
Share on other sites

have you tried it the other way and taken the [] from _unit?

EDIT: ^^ good to see it worked!!;)

Edited by KevsnoTrev

Share this post


Link to post
Share on other sites

yup and thanks again I edited my 1st post the right way above. I'll probably add to it if anyoneelse is interested. Thought about making a new thread to help peeps on my level and below to help others understand scripting this game. lol May just use this one as an example as this script progresses probably slowly over time. Hopefully before Arma 4. lol

Share this post


Link to post
Share on other sites

How about this for all groups?

Just edited your initial post

_array = (_this select 0);
_allgroups = allGroups;
_alive = count allGroups;
_egrp = [];_igrp=[];_wgrp=[];

for "_x" from 0 to (_alive - 1) do {
   _unit = _allgroups select _x;
   _leader = leader _unit;
   _side = side _unit;
   Switch {_side} do {
       East: { _egrp = _egrp + [_unit]};
       West: { _wgrp = _wgrp + [_unit]};
       Independent: {_igrp = _igrp + [_unit]};
   };

hint format ["East: %1\nWest: %2\nInde: %3",_egrp,_wgrp,_igrp];sleep 3;

not sure what you are doing with the leader _unit check but I left it in there..... you might be able to expand to get an array for each side and a leader array for each side...

Share this post


Link to post
Share on other sites

See Ive never messed with Switch. I never fully understood it, but will try this when I get up before work or when I get in from depending on how long I sleep. lol I'll post the results then. lol

As for the Leader part.... That was part of another attempt I was trying that didn't get deleted for 2 reasons. lol 1 I forgot, and 2 may need Leader down the road as a forward observer type deal. ;)

Now I must try to sleep. You have solved a couple week quandary of mine. Didn't want to go to bed till I nipped that one in the bud or had asked for help finally. lol

Thanks again! :)

Edited by Mikey74

Share this post


Link to post
Share on other sites

all good, will see how this progresses and help as I can.

Congrats on your four year birthday with the forums! lol. my actual 35th IRL on 29th August , only reason it resonated with me!!!!.

Share this post


Link to post
Share on other sites

hahahahahahahaha wow I didn't realize. yup and happy 1 for you. AHH if I understood that happy 35th to you too. Close in age. lol I've been tinkering with this stuff sense the 1st OFP in 2001. You'd figure Id know more by now. I've never released anything I've done before. I'm hoping to contribute something to Arma 3 this time around. Anyways. lol now off to bed.

Couldnt sleep so tried the switch command. It didnt work. I tried useing case east..... it worked but all [] were empty. I did figure out how to get the null out of the arrays. by doing this :

_array = (_this select 0);
_allgroups = allGroups;
_alive = count allGroups;
_egrp = [];_wgrp = [];_igrp = [];

for "_x" from 0 to _alive - 1 do {
_unit = _allgroups select _x;
_side = side _unit; 
if ( _side == East) then {_egrp = _egrp + [_unit]};
if ( _side == West) then {_wgrp = _wgrp + [_unit]};
if ( _side == independent) then {_igrp = _igrp + [_unit]};
};
hint format ["East: %1\nWest: %2\nInde: %3",_egrp,_wgrp,_igrp];
sleep 3;

Now Ive figured out how to find all units and groups on map by side. Is there a way to find all markers, or specific markers placed on the map and there names? lol I've looked for this one for months now and cannot find it. I know a few work arounds though, but knowing the markers would be even better. lol

Another question. In the lau language. lol I barely remember this but in a loop I could put something like this _unit[_a] = array and it would rename _unit to _unit1 2 3 4 depending on my loop count. Is there a way to do this in the scripting of Arma.

this way If I want to select a group out of many on east side I could do something like this:

for "_u" from 0 to _alive - 1 do{ 
_unit[_u] =  _allgroups select _u;
};

Obviously this doesnt work on arma... most likely not in LAU but I could do something to that effect and have _unit1, _unit2,_unit3 and so on each = 1 group at a time. I found an array thread for beginners here: http://forums.bistudio.com/showthread.php?100559-Beginners-guide-Arrays I dont have a clue how Ive missed it. Going to read up on it and maybe try to implement what they are teaching into this script and update it when I have it working to what Im trying to accomplish. What I have is a start though. ;)

Edited by Mikey74

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
Sign in to follow this  

×