Jump to content
Sign in to follow this  
Ramsen II

Need help completing sector script (markers in array issue)

Recommended Posts

Hi all.

 

This is a simple version of my sector update script. This version uses markers as sectors, another version changes (hides / un-hides) flags based on ownership.

 

AT moment I would need to copy the code for EVERY sector... pointless, so i want to add all sectors (markers or flags for the flag version) to an array and then update them via the below script.

 

The script works fine with single referenced sectors and updates every 5 seconds or so if aaf are only in the sector it changes green, blue for nato and red lines for contested. Also notifies me of sector updates.

 

So onto the script please i need help with the highlighted text. Type Array expected string. I cannot find way of using for each reference each sector (Marker) in the array with distance to the marker referenced in the unit count code.

 

Quote


_mark = ["a1_35","a1_36","a1_37"]; // 40 sectors in all these are three for testing

 

while {alive player} do

 

    {

 

    _aaf = {alive _x && side _x == RESISTANCE && getposasl _x distance getmarkerpos _mark < radius]} count allunits; /// type array expected string
    _nat = {alive _x && side _x == WEST && getposasl _x distance getmarkerpos _mark < radius} count allunits; /// same...

 

    if (_nat > 0 && _aaf == 0) then

 

        {

 

        if !(markercolor _mark == "colorblue") then

 

            {

 

            _mark setMarkerBrush "solid";
            _mark setmarkercolor "colorblue";

            [Blufor, "BLU"] sidechat "Sector update: Claimed by NATO";

 

            };

 

        };

 

    if (_aaf > 0 && _nat == 0) then

 

        {

 

        if !(markercolor _mark == "colorgreen") then

 

            {

 

            _mark setMarkerBrush "solid";
            _mark setmarkercolor "colorgreen";

            [Blufor, "BLU"] sidechat "Sector update: Claimed by AAF";

 

            };

 

        };

 

    if (_aaf > 0 && _nat > 0) then

 

        {

 

        if !(markercolor _mark == "colorred") then

 

            {

 

            _mark setmarkerBrush "Horizontal";
            _mark setMarkerColor "ColorRed";

            [Blufor, "BLU"] sidechat "Sector update: Contested";

 

            };

 

        };

 

    sleep 5;

 

    };

        

 

 

Please help, so close but cannot complete.

Share this post


Link to post
Share on other sites

***BUMP***

 

Quote

_mark = ["a1_35","a1_36","a1_37"]; // three of the sector marker names.

 

while {alive player} do

 {

    {

 

    _aaf = {alive _x && side _x == RESISTANCE && getposasl _x distance getmarkerpos _mark < 150} count allunits; // type array expected string
    _nat = {alive _x && side _x == WEST && getposasl _x distance getmarkerpos _mark < 150} count allunits; // same...

 

***REST OF CODE***

   }

 } foreach _mark; // this is wrong and does not work - but u see what i want to achieve.

sleep 5;

};

 

 

need help.

Share this post


Link to post
Share on other sites

The problem is that _mark is an array, not a string (as the error "type array expected string" would indicate), so it won't work with either the distance or getMarkerPos commands directly. I think the solution to this would be to do something similar to this
 

 {
	_selectedMark = _x;
	_aaf = {alive _x && side _x == RESISTANCE && getposasl _x distance getmarkerpos _selectedMark < 150} count allunits;
	_nat = {alive _x && side _x == WEST && getposasl _x distance getmarkerpos _selectedMark < 150} count allunits;
 } foreach _mark;

 

Share this post


Link to post
Share on other sites

thx rebel. That was exactly the problem and that is exactly the solution i was looking for. ;)

 

i have 35 odd sectors i had to put into the array, is there someway i can cheat without typing all of them in and by doing something like:

 

Quote

_mark = format ["a%1", _foreachindex];  //just gibberish i know but u see what im getting at... for now i will just type in all the sectors names:

 

_mark = ["a1_1","a1_2","a1_3","a1_4","a1_5","a1_6","a1_7","a1_8","a1_9","a1_10","a1_11","a1_12","a1_13","a1_14","a1_15","a1_16","a1_17","a1_18","a1_19","a1_20","a1_21","a1_22","a1_23","a1_24","a1_25","a1_26","a1_27","a1_28","a1_30","a1_31","a1_32","a1_33","a1_35","a1_36","a1_37"];

 

thx for the help;)

 

p.s for the eagle eyes - yes i do know "a1_29" and "a_34" are missing ;-)

Share this post


Link to post
Share on other sites

You'd have to do something similar to this, I think:
 

_mark = [];
{
_mark = _mark + [format ["a1_%1", _x]];
} forEach [1,2,3,...]

Which would result in _mark = ["a1_1"," a1_2"," a1_3", ...]

Share this post


Link to post
Share on other sites

If you don't know how many markers you are going to have, you may wnat to use the following instead:

_forEachIndex

This will start from 0, if you want to start from 1 then just do:

(_forEachIndex + 1)

You can also use a for-loop.

Share this post


Link to post
Share on other sites

Thx guys,

 

for now i used rebels method which practically still requires me to type in all sector names, but i learned from it + it will also be useful for other scripts.

 

i couldn't get HazJ method to work, not sure how to use the _foreachindex, properly always get 'undefined variable' when using it.

 

i need an example of how to use it properly, using my sector script as an example

Share this post


Link to post
Share on other sites

of course! i was looking under foreachindex page but never saw that one under foreach. cheers  ;)

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  

×