Jump to content
Sign in to follow this  
McArcher

Deleting member from array

Recommended Posts

I have a question about game's code and how it resizes multidimentional arrays.

First, I wanted to delete a member of an array.

Command like

a = a - (a select 1)
will work only for 1-dimentional array, for multidimentional it won't work.

I wrote such code:

// удалÑемÑÑ Ð¸Ð· маÑÑива
private ["_t"];
_ud = _i;
for [{_t=_ud},{_t< (count mcti_airFactories_ru)},{_t=_t+1}] do
{
mcti_airFactories_ru set [_t, mcti_airFactories_ru select (_t + 1)];
};
mcti_airFactories_ru resize ((count mcti_airFactories_ru) - 1); 
publicVariable "mcti_airFactories_ru";

it works fine with multidimentional arrays - first it moves all memebers that are "to the right" (next) from deleting memeber to previous position (1 step to the left) and then I need to delete last member. if I set last memebr to nil this won't work, as there will be ANY instead of last memeber, so I used resize command.

And the question itself:

Is it correct to delete last member by resizing? Won't it create unallocated memory garbage?

Share this post


Link to post
Share on other sites

I'm not *entirely* sure this works, and I don't currently have the time to test, but I think you can do something like this:

_elementToRemove = _i;
mcti_airFactories_ru set [_elementToRemove, "_REMOVE_"];
mcti_airFactories_ru = mcti_airFactories_ru - ["_REMOVE_"];

Now I don't know much about the inner workings of these script commands, so not sure if it'd result in a memory leak, but I highly doubt it.

Note: You can use anything in replace of "_REMOVE_", such as objNull.

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  

×