Jump to content
Sign in to follow this  
tj72

Two Part Question

Recommended Posts

Part 1.

Question:

a. Is it possible to create arrays at runtime that are named Incrementally?

b. Can I create groups at runtime? Do they need to be allready created in the editor. If yes then question 1.a. applies here as well.

Example:

 Within a script I want to create an array.

There is a variable called groupcount to start....

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

Can I name the array as such....

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">eg_+"[(groupcount)]" (please ignore syntax error here)

so that the name of the array is eg_01

It is very important to have the two digit structure. I am assuming I can count # of digits in the groupcount variable  and add zero to the array name so that it is correct and not eg_1 but eg_01.

After the array is created.....

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

so the next array created will be eg_02 and so on up to whatever max groups are. Also another set of arrays would have arrayname_001 format so I figure I would add another layer to the same loop as above.

Part 2.

Question:

a.If group names and an array name are the same, how can I reference the array when the group hits a trigger?

I assume Im allowed to have groupnames and array names as the same with no problem.

b.If for some reason I cant. How can I read the group name and reference the array with the same number as the group.?

Example:

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

sets off trigger and passes a value into the correct array....

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">eg_01 (the array) select 0 = 2

and then that value updates another array....

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">mission_02 select 0 = 2 (but this could be something different)

then use that value to say create a gamelogic named <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">mission_02wp_01

but it could be anything here that is just an example.

The point is that the value of 2 is used in the gamelogics name by pasting it in from the array name.

c.Is it possible to pass the part of an arrays name as a value into another array with generic variables.

Example:

eg_01 is accessed and the value of 1 is passed into a variable of x. Then x is used to access the next array instead of the integer of 1.

Instead of:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if this select 0 = 1 then goto #function_01

its

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this select 0 = x (or should it be _x? not sure)

goto #function_"[x]" (sic syntax)

or

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this select 0 = x(or should it be _x? not sure)

mission_0+"[x]" select 2 = x+1 (so then the array of mission_02 (if x=2) is accessed at the third point on the array)

Any help with this would be a Godsend for me.

Please let me know if this is not clear enough.

Thanks!

Share this post


Link to post
Share on other sites

1:

A: No. The ofp engine isn't smart enough to do that.

B: You can create groups during the mission. See: createGroup

Max groups is 144 groups per side.

2:

A: a groupName and an arrayname can't be the same, ever.

B: name them differently. Groupname = group1 and Array = array1.

C: I'm not sure what you mean here, but I suspect that you're asking if it's possible to get all or part of the variable's name? If that's the case, No. You can only get the value, or in the case of arrays, a pointer to the array.

The best way to do 1A above, is to make put it all in an array in the first palce.

So:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">eg set[groupcount, MyGroup]

If you need two arrays to match, why not just go multidimensional in one array, instead of two seperate?

Just incase you don't know what a multidimensional array is (although you likely do given the nature of the questions you're asking):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">myArray = [[x1, x2, x3], [y1, y2, y3], [z1, z2, z3]];(basically just arrays within arrays)

Share this post


Link to post
Share on other sites

1.A. Doh! Shot out of the sky on that one.

I assumed arrays could hold arrays but Im not sure how they would be implemented here....I could group all of my arrays in larger category type arrays I suppose....

So if I want an array for every group and to interact with them I would have to set up eg_001 through eg_144 at init?

Ok to rephrase and slightly change 2.c.:

Can I take an arrays variable (or pointer) and set that value to another arrays without having a case for each number?

I mean....

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

therefore update ega_"%1[x]"

so that ega_03 is selected if x = 3

instead of

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

if x = 1 then get ega_01

if 2 then ega_02

I thought I could check the name of an array as a string and see if it matches a list of string values at least sad_o.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]a. Is it possible to create arrays at runtime that are named Incrementally?

You mean like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">For [{_ArrayCounter=0},{_ArrayCounter<10},{_ArrayCounter=_ArrayCounter+1}] Do

{

Call Compile Format ["INC_ARRAY%1=[]",_ArrayCounter];

};

That will give you ten global arrays called, INC_ARRAY0..though to..INC_ARRAY9.

Another way:

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

Call Compile Format ["INC_ARRAY%1=[]",ArrayCounter];

If you set ArrayCounter to zero in your init.sqs, this would give you a new global array every time it was called.

Quote[/b] ]Can I take an arrays variable (or pointer) and set that value to another arrays without having a case for each number?

Yes.

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

_Array=Call Compile Format ["INC_ARRAY%1",_Index];

Hint Format ["There are %1 elements in the array",Count _Array]

If _Index=3 then _Array would point to the global array INC_ARRAY3.

Quote[/b] ]If group names and an array name are the same, how can I reference the array when the group hits a trigger?

I'm not sure what you mean by group name. In game group names are WEST 1-1-B e.t.c So you could not use that as a variable name for your array. The syntax would not allow it.

However if you want to coordinate groups with things like arrays, there are a couple of ways, I can think of.

The first, maintain an array of all the groups in your mission, using the position of each group to create your array. So you would have:

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

GROUP_INDEXLIST=GROUP_INDEXLIST+[_Group];

Call Format ["GROUP_ARRAY%1=[]",(Count GROUP_INDEXLIST)-1];

Again GROUP_INDEXLIST has to be initialised before hand. To then get the groups associated array, from say a trigger.

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

_Index=GROUP_INDEXLIST Find _Group;

_Array=[];

If (_Index!=-1) Then

{

_Array=Call Compile Format ["GROUP_ARRAY%1",_Index];

};

Hint Format ["Array : %1",_Array];

The other way, is to assign the array to each of your group members using the setVariable and getVariable commands. That way you can grab the array from any of the groups units, from within your trigger.

Share this post


Link to post
Share on other sites

Outstanding.....

I will try this as soon as I can but its good to know what is possible.

I will definately make arrays for my different array types. Since they are incremental names I should be able to locate an array by its count on the array, because they should be the same.

Im almost positive I can take the ingame group name such as WEST 1-1-B and pass it into an array as a string and register that ingame name to an array. I should be able to do it at mission start and when a group is created on the fly hopefully.

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  

×