Jump to content
Sign in to follow this  
terox

Problems removing masterarray element

Recommended Posts

I am trying to get a looping system to remove the selected Masterarray element when  it's subarray  is empty

The following system is a simplified version of the actual system showing only the pertinent information

<span style='color:Blue'>INIT.sqs</span>

Quote[/b] ]<span style='font-size:10pt;line-height:100%'>;;;Sub Arrays

tx_AmbushArray = ["Missions\AmbushA.sqs","Missions\AmbushB.sqs","Missions\AmbushC.sqs"]

tx_AssasinArray = ["Missions\AssasinA.sqs","Missions\AssasinB.sqs","Missions\AssasinC.sqs"]

tx_RecceArray = ["Missions\RecceA.sqs","Missions\RecceB.sqs","Missions\RecceC.sqs"]

;;;Master Array

tx_Minimissions = [tx_AmbushArray,tx_AssasinArray,tx_RecceArray]</span>

When required (via booleans and a monitoring script not shown) the following chain of scripts is run in this order

<span style='color:Blue'>SERVER_SELECT.sqs</span>

(Server side script which randomly picks a master element position and a sub element position of the master element

Quote[/b] ]<span style='font-size:10pt;line-height:100%'>?!(local server):exit

#START

tx_selectmission = false

#TYPE_SELECT

;; selects the master array element

tx_AA = count tx_minimissions

?(tx_AA < 1): goto "END"

tx_A= random tx_AA

tx_A = (tx_A - tx_A mod 1)

?(tx_A == tx_AA): tx_A = tx_A - 1

#MISSION_SELECT

;; selects a subarray element of the masterArray element

tx_BB = 0

{tx_BB= (Count _x)} ForEach tx_Minimissions select tx_A

tx_B= random tx_BB

tx_B = (tx_B - tx_B mod 1)

?(tx_B == tx_BB): tx_B = tx_B - 1

tx_sendmission = true

#PV

{PublicVariable _x;}foreach["tx_A","tx_B","tx_sendmission"]

exit

#END

hint "Debug NO MORE MISSIONS AVAIL"

exit</span>

Once the above script has run it's course, the next script is then started up by a script monitoring the booleans (not shown)

<span style='color:Blue'>ALL_SET.sqs</span>

Having received the public variables, this "local to all" script then selects the actual element that the random script decided on and then processes it  

eg [] exec _mission

Quote[/b] ]<span style='font-size:10pt;line-height:100%'>#START

tx_sendmission = false

#SET_MISSION

_minimissions = tx_minimissions

;;following is array created from masterArray element

_type = []

_type = _type + (_minimissions select tx_A)

;;following creates variable for  the actual sting element  in the sub array

_mission = _type select tx_B

_type = _type - [_mission]

_count = count _type

_minimissions set [tx_A, _type]

<span style='color:Green'>?  (_count  < 1): hint "Debug: Sub Array Empty" </span>

;;The following line needs to remove the element from the masterarray if its subarrays are empty. (This is where my problem lies

as you can see i have tried many possibilities only a few shown here)

<span style='color:blue'>;;? (_count  < 1):_Minimissions = _Minimissions - (_minimissions select tx_A)

;;? (_count  < 1):_Minimissions = _Minimissions - [_minimissions select tx_A]

;;? (_count  < 1):_Minimissions = _Minimissions - _type

? (_count  < 1):_Minimissions = _Minimissions - [_type]</span>

tx_minimissions = _minimissions

[] exec _mission

exit

#END

hint "NO MORE MISSIONS"

exit</span>

once the _Mission that this script starts has run its course, it then starts up the <span style='color:Blue'>SERVER_SELECT.sqs</span> and the loop continues

The problem is, when the subarray is empty and _count <1, i cannot remove the relevant array element from the _minimissions (tx_minimissions) array

the green coloured line is run, so the script does see the subarray as empty

so when the loop restarts at the server_select.sqs, the script still see's in this example 3 elements in the master array and thus is able to select a sub array which is empty

this then causes the loop system to fail

when running a debug, ,

_type or _minimission select tx_A returns the contents of the subarray

not the actual masterarray element. eg "tx_RecceArray"

In advance........Many thanks for any help offered

Share this post


Link to post
Share on other sites

Something like this maybe?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#START

tx_sendmission = false

#SET_MISSION

_minimissions = tx_minimissions

;;following is array created from masterArray element

_type = []

_type = _type + (_minimissions select tx_A)

;;following creates variable for  the actual sting element  in the sub array

_mission = _type select tx_B

_type = _type - [_mission]

_count = count _type

_minimissions set [tx_A, _type]

?  (_count  < 1): hint "Debug: Sub Array Empty"

;;The following line needs to remove the element from the masterarray if its subarrays are empty. (This is where my problem lies

_temp1 = 0

_temp2 = 0

{IF (count _x == 0) then {IF (_temp2 != 0) then {_temp1 = _temp1 + 1} else {_temp2 = 1};_minimissions set [_temp1,"tempstring"]}} foreach _minimissions

? (_count  < 1):_Minimissions = _Minimissions - ["tempstring"]

tx_minimissions = _minimissions

[] exec _mission

exit

#END

hint "NO MORE MISSIONS"

exit

As you can see I put a Foreach line in there, which goes through the array looking for empty [] arrays, and changes them to "tempstring", then the line you had before now simply takes "tempstring" away from the master array.

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D
Quote[/b] ]

array resize count

Operand types:

   array: Array

   count: Number

Compatibility:

   Version 1.75 required.

Type of returned value:

   Nothing

Description:

   Change array size. Can be used to add or remove elements from the array.

Example:

   array resize 2

wink_o.gif

Share this post


Link to post
Share on other sites

I'm not sure I get it, so only brief:

example: I have an array with the empty subarrays:

_a=[[1,2,3],[],["a","b","c"],["alpha"],[]]

and I want to change it to the array without the empty subarrays:

_a=[[1,2,3],["a","b","c"],["alpha"]]

If it's so, then I can use:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_tmp=[]

{if (count _x>0) then {_tmp=_tmp+[_x]}} foreach _a

_a=+_tmp

tested

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D
Quote[/b] ]t_d? here?  

welcome!  

Yes and thx. But i wont post much here. I dont like to speech english. Sry guys    rock.gif

But i will try it wink_o.gif

What happens when you write this :

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">masterarray -[] rock.gif

Share this post


Link to post
Share on other sites
T_D @ June 30 2004,10:03)]What happens when you write this :

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">masterarray -[]

 rock.gif

Nothing:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_a=[[1,2,3],[],["a","b","c"],["alpha"],[]]

_a=_a-[]

_a=_a-[[]]

_a=_a-["alpha"]

_a=_a-[["alpha"]]

hint format["%1",_a]

And the result is:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[[1,2,3],[],["a","b","c"],["alpha"],[]]

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_i = 0

_ma = [[1,2,3],[],["a","b","c"],["alpha"],[]]

_ha = []

_anz = count _ma

#loop

_a = _ma select _i

?(count _a >= 1):_ha = _ha + _a

_i = _i + 1

?_i >= _anz : goto "next"

goto "loop"

#next

_ma = _ha

exit

_ma = Masterarray

_a = Array

_ha = Helparray

Hope this works

Share this post


Link to post
Share on other sites
T_D @ June 30 2004,16:35)]_i = 0

_ma = [[1,2,3],[],["a","b","c"],["alpha"],[]]

_ha = []

_anz = count _ma

#loop

_a = _ma select _i

?(count _a >= 1):_ha = _ha + [_a]

_i = _i + 1

?_i >= _anz : goto "next"

goto "loop"

#next

_ma = _ha

exit

does exactly the same as my example:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_a=[[1,2,3],[],["a","b","c"],["alpha"],[]]

_tmp=[]

{if (count _x>0) then {_tmp=_tmp+[_x]}} foreach _a

_a=+_tmp

Share this post


Link to post
Share on other sites
Guest [B.B.S.] T_D
Quote[/b] ]does exactly the same as my example:

Sry didnt see.

Share this post


Link to post
Share on other sites

not much of a scripter myself but i found this in the UN-Official Tut.

Quote[/b] ]Array

Description :

How to use an array (list of elements)

Syntax :

MyArray = ["MyText1","MyText2",value, variable]

MyArray List of elements (array)

You can make a concatenation like this:  

MyArray1 = ["One", "Two"]

MyArray2 = ["Three","Four"]

GroupingArray = MyArray1 + MyArray2

GroupingArray now contains "One", "Two","Three","Four"

You can remove element in array too:

MyArray1 = ["One", "Two","Three"]

MyArray2 = ["One"]

GroupingArray = MyArray1 - MyArray2

GroupingArray now contains "Two","Three"

To remove the third element in an array:

MyArray = MyArray - [MyArray select 2]

Returns :

N/A

Example :

A short example to add a given player to an array (check if it isn't in array before you add it):

_Player = _this select 0

?!(_Player in PlayersArray):PlayersArray = PlayersArray + [_Player]

And how to remove it:

_Player = _this select 0

?(_Player in PlayersArray): PlayersArray - [_Player]

Where PlayersArray is an array variable containing a player list, in this case.

MyString = format ["Target Name/Pos: %1, %2", EnemyUnit, getpos EnemyUnit]

I hope it helps   smile_o.gif

Share this post


Link to post
Share on other sites

Thx for all the replies folks

the end answer was to simply set the type of variable element to anything but a string, eg boolean or integer before i tried to remove it

in this case, very crudely

_tempA = 1

? (_count  < 1):hint "Debug Array empty"

? (_count  < 1):_minimissions set [tx_A, _tempA]

? (_count  < 1):_minimissions = _Minimissions - [_tempA]

The If....Then statement offered also works just as well

I still have a slight bug in the script.

90% of the time, when i set a debug mode to loop through every script exec once eventually leading to the "No More Mission" hint message.

However on the odd occasion the loop sometimes fails reporting tx_B as being "string oxcliffe" error, because sometimes, for a reason as not yet known, it trys to select an element in a subarray array that is empty

I havent had time to debug this error yet, however when i do, i will post the full working system as i am sure it will be of use to some who want to have a random "Script" execution system"

Thx for your efforts, very much appreciated

This system script by the way is part of the backbone of a 27 minimission coop randomly selected within 1 big coop

Like a campaign but all in 1 mission

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  

×