Jump to content
Sign in to follow this  
mad rabbit

What is in an empty array?

Recommended Posts

I was trying to debug a bunch or arrays for my CTI map and I came across a problem in terms of definition.

For example if I define:

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

emptyArray = []

then upon initialization of my map whilst debugging, try to check if that array is still empty by:

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

;DEBUG

_cmdr = _this Select 0

_debugarray1 = "OBJ HERE"

_obj = emptyArray select 0

?(isNull _obj):_debugarray1 = "NO OBJ";

_debugarray2 = count emptyArray

DEBUGGING = Format ["emptyArray = %1, count of emptyArray = %2",_debugarray1,_debugarray2]

_cmdr groupChat DEBUGGING

emptyArray always = "OBJ HERE" despite the count = 0.  I've also tried in the above doing a check via:

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

?(_obj == objNull):_debugarray1 = "NO OBJ";

but still get the same result.

So my question is:

What is between the brackets "[]" in an empty array?

Share this post


Link to post
Share on other sites

Nothing is between brackets and calling array select 0 is an error when the array is empty.

My explanation is: assignment in _obj = emptyArray select 0 is not done because of the error (or, if it is, _obj is assigned a void value - meaning it is nondefined and _obj variable is destroyed). Therefore the condition isNull _obj is not satisfied later and original value is still present in _debugarray1.

Share this post


Link to post
Share on other sites

OMG THAT WAS QUICK!! Posted ~5min ago LMAO.

Thanks Suma!

So if my terminology is right (this is main thing I have problems with), how do you detect if an array, which is defined in the manner I described during map initialization, contains 'nothing'?

Share this post


Link to post
Share on other sites

You already have it in your code: count array == 0.

Share this post


Link to post
Share on other sites

Oops! got ahead of myself.  The 'real' question I should have asked about arrays is:

If I have:

Defined when the map is started

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

;Stated at initalization

ArrayA1 = []

ArrayB1 = []

ArrayC1 = []

ArrayA2 = []

ArrayB2 = []

With the following being updated via a continuous loop.

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

;Updated via a continuous loop

ArrayY = ArrayA1 + Array B1 + Array C1

ArrayZ = ArrayA2 + Array B2

ArrayCombined = ArrayY + ArrayZ

Then I add a single object to ArrayA1 via the following for example:

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

;From a seperate 3rd script

ArrayA1 = ArrayA1 + [_newobj]

EXIT

1)The count for ArrayX increases to 1 but the count for ArrayA1 stays at 0. I'm sure this is due to the update being done only for ArrayX via a loop and not ArrayA1.  How can I avoid this problem if I must state that ArrayA1 is empty upon initialization of the map?

2)If I was to add an object to ArrayA1 and then to ArrayA2 via:

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

;From a diff but still seperate 3rd script

ArrayA1 = ArrayA1 + [_newobj1]

ArrayA2 = ArrayA2 + [_newobj2]

EXIT

Is the object in ArrayA2 accessiable/retrieveable in ArrayCombined via:

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

_attempt1 = ArrayCombined select 3

OR

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

_attempt2 = ArrayCombined select 1

If not _attempt1 then how would I make it so that it is selectable via _attempt1 using the array setup I just described?

I was thinking of detecting if a particular set of arrays were 'empty' OR [], hence the rather silly question before in order to avoid them being listed in a Combo_box I've made.  Or possible initializing the arrays with the string "avail" in them and detecting for that, and skipping adding them to the Combo_box if they had the string "avail" in them.

Anyway, thanks for the help Suma.

Share this post


Link to post
Share on other sites

1) You sure arrayCombined isn't 0 instead of ArrayA1? Because you just did add that thing there and I concluded that with a little experiment. And it would support the way arrays are dealt with, once you've declared one, it won't change by adding another array by name to it, instead try the set command. Or...

2) In order to get _attempt1 you might wan't to look at the following (how I did the equivalent of your arrayCombined, and what you seem to be aiming at):

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

_initairShells = [OFPTF_SPDlgbShellsC,OFPTF_SPDnapaShellsC,OFPTF_SPDclusterShellsC]

_initartyShells = [OFPTF_SPDartyShellsC,OFPTF_SPDartyFlaresC,OFPTF_SPDartySmokesC]

_initmortShells = [OFPTF_SPDmortShellsC,OFPTF_SPDmortFlaresC,OFPTF_SPDmortSmokesC]

_initassetshells = [_initairShells,_initartyShells,_initmortShells]

Hope that isn't too hard to read. But anyway, at the end I combine 3 arrays into 1 array as array = [stuff,stuff,stuff] instead of your array = stuff + stuff + stuff. That way you'll have something looking like [[],[],[]]. But now you'd have to catch the inserted item by

_attempt1 = ((array select 0) select 1)

for instance. Ok enough of my ramble. I hope you got some clues. I certainly am I bit puzzled as what your after wink_o.gif

Share this post


Link to post
Share on other sites

I found the problem. It was to do with my debug and not the addition or removal of objects from the array. i.e. I was adding to one array but using format to check a different array. Oops!

Anyway, the solution you gave looks great. Although my method still works, it does give me another way if my downstream scripting has troubles with the way I combined the arrays.

I found the discussion titled "count help" start by Hakon_H and involving The_Taurus and RED interesting. In particular,

Quote[/b] ]

Multidimentional = [[],[]]

OFP can't handle: multiArray = [] []

From what I understand I haven't constructed a multiArray but a mutlidimensional/nested array, right?

In addition, your described method of getting _attempt1 to work was also very helpful, I'll use it if it doesn't work the direct way. Thanks!

Share this post


Link to post
Share on other sites

rock.gif?

/*-----------------------------------------------------------------

CutInSubArray function

Cuts and rezise in an subarray

Called with:

[<pos subay in array>,<posInsubarray to cut>,<array>] call CutOutOfArray

Requires:

cutoutofarray.sqf to be preprocessed and present in the mission dir.

------------------------------------------------------------------*/

private ["_x", "_Array","_PosInArray","_SubArray ", "_N", "_i", "_TempArray","_Temp"];

_Array = _this select 2;

_PosInArray =  _this select 0;

_x =  _this select 1;

_SubArray = _array select _PosInArray;

_TempArray = []; <----just init but never test it at this point it's my rule, maybe wrong it's the count == 0 smile_o.gif

_N = count _SubArray;

_i = 0;

while {_i < _N}

do

  {

  _temp = _SubArray select _i;

     if (_i != _x) then {_tempArray set [count _tempArray, _temp ]};

  _i = _i + 1;

  };

_Array set [_PosInArray ,_Temparray];

_Array

Share this post


Link to post
Share on other sites
I found the problem. It was to do with my debug and not the addition or removal of objects from the array. i.e. I was adding to one array but using format to check a different array. Oops!

Anyway, the solution you gave looks great. Although my method still works, it does give me another way if my downstream scripting has troubles with the way I combined the arrays.

I found the discussion titled "count help" start by Hakon_H and involving The_Taurus and RED interesting. In particular,

Quote[/b] ]

Multidimentional = [[],[]]

OFP can't handle: multiArray = [] []

From what I understand I haven't constructed a multiArray but a mutlidimensional/nested array, right?

In addition, your described method of getting _attempt1 to work was also very helpful, I'll use it if it doesn't work the direct way. Thanks!

As far as I understand you created a one dimensional array. tounge_o.gif hehhehe

You just added the elements together back to back. To create a multi dimensinal array you would do

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

ArrayB1 = []

ArrayC1 = []

ArrayY = [ArrayA1,Array B1,Array C1]

Share this post


Link to post
Share on other sites

Or you use

Quote[/b] ]ArrayY = ArrayY + [ArrayA] + [[valueB]]

-> ArrayY = [ArrayA,[valueB]]

Share this post


Link to post
Share on other sites

Sorry?

EDIT: Ok, I get it, you are showing how to create some multidimensional array, I was just showing him how he would create what he was thinking of.

Share this post


Link to post
Share on other sites

Thanks all for the feedback!

I have done some more testing and have discovered that in my map a multi-dimensional array is the best way to go as the reference point for an obj in this type of array is fixed. Just referencing it is rather annoying but I figured it out.

i.e. In the following example I will be able to retrieve object in Array B1 via:

_nestedasset = (((ArrayTotal select 1) select 0) select 0)

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

ArrayA1 = []

ArrayA2 = []

ArrayA3 = []

ArrayB1 = []

ArrayB2 = []

ArrayX = [ArrayA1,ArrayA2,ArrayA3]

ArrayY = [ArrayB1,ArrayB2]

ArrayTotal = [ArrayX,ArrayY]

If I was to add an obj to the arrays in my second post in this thread, that position would NOT be fixed. This would've caused major problems also later with objects shuffle position once the one in the position before them is removed.

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  

×