Jump to content
Sign in to follow this  
breeze

Trying to create array

Recommended Posts

I am trying to create a script that lists the members of a squad Each soilder has a name and those names are listed in a file called sq1.sqf

In the File Sq1.sqf is

sq1 = [bill,joe,susan,etc] Now comes the confusion I have it listed as sq1 instead of _sq1 because when I put it into my load way point _sq1 is not allowed I am trying to create the group so within a trigger or waypoint I can quickly add a group name for load and unload

However I keep tripping and falling over the local and global errors?

So basically I want to create the group as an array name I can refer to...

Also if I use incorrect terms within this post please point them out to me.

As I am under the impression because I am referring to multiple objects within the bracket it makes it an array?

Thanks in advance gentlemen

Share this post


Link to post
Share on other sites

When you create a variable with an underscore as the first character, it is a local variable. Creating a variable without an underscore makes it a global variable that is accessible to all scripts/everything in the mission. Local variables are not allowed to be used in the editor.

Share this post


Link to post
Share on other sites

Ok so to create a squad that I can launch from a trigger or waypoint requires a global variable...

sq1 = [tom,dick,harry] <------ that is proper use of a global variable which can be used by any trigger or way-point? That is what I have in my mission folder with an [] execVM sq1.sqf (which is the file name) in my init.sqf however this is not working I get an error

Share this post


Link to post
Share on other sites

First off, you do not need to create a new file just to store an array. That array could be declared anywhere from your init.sqf file to the initialization field of any unit in the editor to the activation field of any trigger with condition "true" (activates automatically at mission start). Since you're already using an init.sqf file, that would probably be the easiest place to store it. All you need to do is add the following line to your init.sqf file:

sq1 = [tom,dick,harry];

That's it. Now, after your mission loads, the variable sq1 will return the array [tom,dick,harry].

The question then becomes, "what do you want do with this array?" And I am a little confused about that based on your description, so you'll have to clarify.

Share this post


Link to post
Share on other sites

I just want to be able to use it in waypoints and or triggers to loadincargo for a chopper or a truck then move them as a group into different objectives....

So what you posted so I do not miss it my array is a global array? This array has to be global to be used in a trigger or waypoint? and an array can be declared anywhere within the game? so I could also place it in the init field of any of those ai fields,

Share this post


Link to post
Share on other sites
So what you posted so I do not miss it my array is a global array? This array has to be global to be used in a trigger or waypoint? and an array can be declared anywhere within the game? so I could also place it in the init field of any of those ai fields,

That is correct.

However, you should know that the game handles groups in a special way. A group is not simply an array of units; it is actually its own entity with its own properties. In ArmA, every unit is the member of a group, even if it's the only member of that group. To find out what group a unit belongs to, you can use the group command. If Tom, Dick and Harry are grouped together in the editor (indicated by a light blue line), then running "group Tom", "group Dick" and "group Harry" would all return the same result. To save this result (Tom, Dick and Harry's group) to a variable, you can simply assign it like so:

init.sqf:

sq1 = group Tom;

A typical practice for saving group variables is to use the init field of group leaders you wish to save. Because you are working in a unit's init field, you have access to the special variable "this," which refers back to that unit whether or not you have named it.

Group leader's init field:

sq1 = group this

Note that you don't actually have to use the group leader; as stated above, using any unit in the group would produce the same result, but using the leader makes it easier to keep track of things in the editor. For multiplayer scenarios where the group leader in the editor might not exist (which would happen if no player occupied this unit's slot and AI was disabled), you may want to consider copy and pasting the line into the init field of every unit in a group just to be sure.

Now that you have your group saved to a variable, you can do several things with it. Certain script commands, like addWaypoint, require a group input to function. Other commands will require individual units as input. In this case, you can get an array of all units in a group at any time with the units command. You should reference the Biki to see what kind of input is required for the command you wish to use.

Hope that helps.

Share this post


Link to post
Share on other sites

Ok I love that I can make it that easy, because a group is handled differently but I still get this error;;;;;

I have a group with way points a trigger activating it by being synced with the second way point, that part works however the fifth way-point is a get in way-point and in its activation line I have sq1 moveincargo chopper2;

if the sq1 is declared as a group I am not sure why it is not working? As I tried it with one group members name and it worked as soon as I tried to add more than one name or a group name I continually fail.

Oh and one more question about the groups then, you are saying if I place groups with the editor as long as the have the blue lines I don't even needs to name them just sq1 = this, sq2 = this, sq3 etc???

Says error sq1 error type group expected object

I also tried this syntax from killzone in other forums

sq1 assignAsCargoIndex [chopper2, 1];

Edited by Breeze

Share this post


Link to post
Share on other sites
sq1 = [tom,dick,harry] <------ that is proper use of a global variable which can be used by any trigger or way-point? That is what I have in my mission folder with an [] execVM sq1.sqf (which is the file name) in my init.sqf however this is not working I get an error

Remember to close every statement with a semicolon ( ; ). Otherwise, this is the correct way to create a variable in .sqf. The problem with this code, however, is that if you intended to store the names tom, dick, and harry, they will not be stored because you actually referring to variables named tom, dick, and harry. If you were trying to actually store the words themselves, you'd need to enclose each word with double quotation marks. These are known as strings

sq1 = [tom, dick, harry]; //variables
sq1 = ["tom", "dick", "harry"]; //strings

Share this post


Link to post
Share on other sites

Ok this is a problem for me I read the tutorials to know what you said here however, I still don't understand exactly what it is I want when I want it. I understood a string to be used as just text in other words if the above string were used it would only be to maybe print on the screen it really had not other function?

The variable that is not a string I am able to use as an object like a command to do something and sq1 is used instead of writing the 4 objects. and as I was corrected above this works a little different as a group..

So hopefully I am understanding this correctly

But I am not able to use this in my trigger and it is making me crazy

once i declare my variable in an init field of an already established group as sq1 = this;

Then I should be able to call it in a trigger or waypoint right?

So in my last waypoint i have it listed as getin waypoint and in that activation line I have sq1 moveincargo chopper2;

I get an error that it is getting a group instead of an object?

Share this post


Link to post
Share on other sites
Says error sq1 error type group expected object

Yes, this is because moveInCargo cannot take a group as an argument. If you want to move everyone in a group into the cargo space of a vehicle, use:

{_x moveInCargo chopper2} forEach (units sq1);

What that code is really doing is 1.) Getting the units in the group sq1 ("units sq1") 2.) for each unit in that array ("forEach"), the code in curly braces {} is run 3.) this code takes the currently selected array element ("_x") and attempts to move it into the cargo space of chopper2.

Keep in mind, though, that moveInCargo will instantaneously move a unit into a vehicle; there will be no animation, so it's basically teleportation. If you simply want a group to get into a helicopter, you can achieve this entirely without scripting. Simply give the group a "GET IN" waypoint in the editor, and then synchronize this waypoint (use F5 for synchronize mode) to one of the chopper's waypoints at the desired loading zone.

Share this post


Link to post
Share on other sites

Feeling like a bit of a dunce having read that tutorial and still not following aspects of this, When I used the _x I got an error using a local variable in a global space, so if I bracket the local variables it keeps them local instead of global? because that is what you did differently.

Also I would like to keep the animation if possible when I run that though they don't get in..do I need a condition? all I have is the sq1 = group this in the init line of the squad leader. then my way-points run to the chopper last one is a get in the second way point is synched to a second way point to initiate it that works

---------- Post added at 01:27 ---------- Previous post was at 00:11 ----------

But they dont get into the chopper

Share this post


Link to post
Share on other sites

You're trying to do too many things at once, which is naturally going to be overwhelming. Start small. Figure out how to get the units into the chopper using waypoints alone. There is no need to put anything in any activation field; there is no need to store the group or its members as a variable/as variables. Just try this:

  1. Create your infantry group in the editor. Give it a "GET IN" waypoint at the location where you want your group to get into the chopper.
  2. Create your chopper in the editor. Give it a "MOVE" waypoint near (but not directly on top of) the location of your infantry group's "GET IN" waypoint.
  3. Synchronize your infantry group's "GET IN" waypoint to your chopper's "MOVE" waypoint using the synchronization tool in the editor (shortcut: F5).
  4. OPTIONAL: To have more control over the exact position at which the chopper will land, place an "H" object (found under Units Mode (F1) > Empty > Objects) at the LZ location. AI pilots will prefer H locations when landing. If you don't want a visible helipad, you can use the "H (Invisible)" object.

Before you go any further with scripting, I would strongly recommend getting the above to work.

Share this post


Link to post
Share on other sites

Ahhh my chopper is empty the player gets in to move the group of infantry

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  

×