Jump to content
Sign in to follow this  
m0nkey

new array index = createMarker (or any object creation with arrays) - help?

Recommended Posts

Not sure exactly how to word this, have seen others mention it but cannot find where it is.

Basically, in other script languages, one might create something like a button

$button = createbutton(params)

If you were working on a form or something similiar, with many buttons or objects, you would essentially store the "handle" to the objects in an array index element, like this (no specific language used, just laymans terms lol )

array[1][2] = createbutton(params)
array[2][2] = createtext(params)

However, how does one do this in the sqf script language? If we look at createMarker, it states

variable = createMarker ["string name",position];

so, if we used set with an array, how would we accomplish things? Or do you just set it with a variable already created? like..

_obj = createMarker ["name1",_posX];
array set [count array,_obj];

I ask because in other languages, the handle to the object can be referenced, which it can in arma as well, but getting it in there without creating the object first (ie. _obj = ) is something I have not been able to figure out how to do.

Is it possible? Any good tips on working with arrays holding handles/references to objects that one wishes to delete/destroy later? Always open to learning something new lol.

Share this post


Link to post
Share on other sites

Sorry if I'm not understanding is this what your referring to?

it will store the spawns in an array for later use without spawning on creation.

array=[];
test = compile "what = createVehicle ['B_MRAP_01_F',getpos player,[],0,'']";
array set [count array, test];
test1 = compile "what = createVehicle ['B_Truck_01_mover_F',getpos player,[],0,'']";
array set [count array, test1];

spawn using

call (array select 1);
// 0='B_MRAP_01_F'  and 1 = 'B_Truck_01_mover_F'

Share this post


Link to post
Share on other sites

thats really neat for sure. Had not thought to actually compile the code into the array and then call the array. very neat.

But what I mean is if you can say, in very laymans terms

array index set = createVehicle [params]

or if you MUST use a multiple step process, ie

_obj = createVehicle [];
array set [count array, _obj];

Its not a super critical thing, its just that (in the case of createMarker as an example) your handle = marker when you create it, so I wonder how you do that in one step with an array, as there is no "=" method I know of to use with it, it only uses set.

Since createMarker wants an = sign, I would think this at first (as it applies to an array that is not using select statements like a query, which is how arma does it, so strange)

(array select x) = createMarker ["name",posX]

Its just one of those strange array things I am trying to adapt to when it comes to arma's arrays. Always trying to be aware of well structured code and optimized code, so just trying to see if there is a one step method.

Thanks for taking the time to respond!

edit: oh, the whole idea is to create lets say 3 markers and 3 vehicles or waypoints or 3 groups or whatever. An array holds thier "handles" so that when it comes time to clean up the task/mission/objective/whatever, all you need to do is step through the array and delete the index (bearing in mind the different commands used for vehicles vs markers vs waypoints etc). I use arrays to hold handles to objects all the time in other applicaitons than a game script..

Share this post


Link to post
Share on other sites

I'm probably wrong but I don't think you can unless it's compiled or a string and then compiled on use.

You can change the variables in the string using format. %1 will be _pos

array=[];
_pos = getpos player;
array set [count array,format ["what = createVehicle ['B_Truck_01_mover_F',%1,[],0,'']",_pos]];

on use

call compile  (array select 0);

So it is sort of one line.

Share this post


Link to post
Share on other sites

Thats sort of how I figured it would be. I was double checking because it seems so counter productive to me, needing two steps to do something like that.

The question with your example I have is, if you do the call compile on that code that lies within the array index, the array index will not equal the handle or reference to the created vehicle. The variable "what" would do that. Correct?

So what I am looking to do is actually have the value of the array index be the handle to an object. Which I can do in a two step process. And it seems thats the only way to do such a thing.

Thanks yet again F2k for your time :)

EDIT: which actually leaves me with another question. (sorry)

Suppose i do this

for "_i" from 0 to 5 do
{
 _obj = createVehicle [....];
array set [count array, _obj];
};

will the value of _obj be put into the array? Or is it a copy of _obj? Or is it a reference? If I re-use _obj in a loop like that, are the array values changed? lol, cannot test this until tomorrow night but it just occurred to me that what I would normally do with an array is actually create the vehicle with the array index = equaling the returned handle. I know arrays in sqf are references unless you use a copy, but have not seen what happens with handles put into arrays....

Edited by m0nkey

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  

×