Jump to content
Sign in to follow this  
rejenorst

Array set [_index,_value] problem.

Recommended Posts

Ok I have a large global array that has a lot of information stored in it called missionparam.

When I want to access a list of objectives (they're markernames) from the array I do:

_objectives = missionparam select 4;

(this will estract an array within the global array: ["obj213414","obj12321",etc..];

The problem starts when I want to use the set command to remove the first objective from teh local variable like so:

_objectives set [0,1];

_objectives = _objectives - [1];

Also tried this:

_objectives set [0,"remove"];

_objectives = _objectives - ["remove"];

What ends up happening is that the changes are also done to the global variable even though I am editing the local copy of the variable. The global variable being: (missionparam select 4)

has this happened to anyone else and is there an easy explanation? Thanks.

if I take out the objective by doing this:

_objectives = _objectives - [_objective];

It works fine but Id like to know what's going on.

Edited by Rejenorst

Share this post


Link to post
Share on other sites

_objects =+ missionarray

will make a copy of it, what you are doing is pointing to the array.

Share this post


Link to post
Share on other sites

Awesome thank you very much for the pointer Squ33z3!!!

That explains it. Cheers.

Share this post


Link to post
Share on other sites

I never use set personally, inconvenience of having to keep track of the index. Just add to the array with _arr = _arr + _entry;

Share this post


Link to post
Share on other sites

set is much faster tho.

And it's really easy if you're just adding values, such as

_temp = objNull;
_myArr set [count _myArr,_temp];

Share this post


Link to post
Share on other sites

The main reason I want to use set is just for efficiency and try to keep CPU load down. In any case I may have also used private[""]; inside a bracketed section of code which may have been the problem.

Share this post


Link to post
Share on other sites
My local variables are declared as private.

Yeah but you need to change scope for it to be useful.

What I gather, is you defined _objectives as private, and then use _objectives as a pointer to a global variable, right?

I think this would work if you defined _objectives as missionparam select 4 in a scope, and then private that variable inside a smaller scope (called function, control structure, ...), execute your operations on it.

I might be wrong though.

Share this post


Link to post
Share on other sites

Ah cheers BlackMamb. I'll need to look into this more carefully as I thought declaring something as private at the start of a script (outside a scope ie: {}) would negate any problems when used in other scopes within the script.

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  

×