Sign in to follow this  
Followers 0
Sentrex

Arrays

1 post in this topic

What are arrays?
In simple terms, an array is a whole load of different elements which are all collected together by the program and given one single name.
 
Basic knowledge of arrays
An array uses square brackets [ ] to tell the program which part of the array you want to focus on.



array = [ 1, 2, 3, 4 ,5 ];
print( array[1] ); // "2" would be printed since the first term is 0
print( array[4] ); // "5" would be printed for the same reason

 
How arrays can be used in COD4
Arrays are very useful when it comes to mapping/modding in COD4. One of the fundamental ways to use arrays is by doing a For loop. I have explained how these work below.
 

for( i = 0 ; i < 5 ; i++ )
{
iPrintLnBold( "loop" );
}
 
OUTPUT: 
loop
loop
loop
loop
loop
 
So basically, 
i = 0 means i starts off at 0
i < 5 means i needs to be LESS THAN 5
i++ means each time it loops i is increased by 1
 
Lets think about this logically:
if i is increasing by each time "loop" is printed AND i needs to be less than 5 then it can only be printed 5 times.
 
So, it would be like this:
 
 
i = 0
print( "loop" );
i is increased by one
<GO BACK TO START>
i = 1
print( "loop" );
i is increased by one
<GO BACK TO START>
i = 2
print( "loop" );
i is increased by one
<GO BACK TO START>
i = 3
print( "loop" );
i is increased by one
<GO BACK TO START>
i = 4
print( "loop" );
i is increased by one
<GO BACK TO START>
i = 5
Since i is no longer LESS THAN 5 the loops stops.

 

Using For loops to initialize all elements of an array (Pixel, look here)
 

effect_origin = getEntArray( "NameOfOrigin", "targetname" );
for( i = 0; i < effect_origin.size; i++ )
{
playFX( effectname, effect_origin[i].origin );
}

The program searches your map for all entities with the targetname of NameOfOrigin and gives them all one name; in this case it's effect_origin.
The for loop means that it will loop the 'playFX' line with i = 0 all the way up to i = effect_origin.size, There for it will play the effect at each different location for effect_origin and then stop. If you're having trouble understanding this then re-read the section on For loops.
 
Common uses of arrays in Call of Duty 4
 

players = getEntArray( "players", "classname" );
for( i = 0; i < players.size; i++ )
{
        players[i] thread blah():
}
platforms = getEntArray( "name", "targetname" );
for( i = 0; i < platforms.size; i++ )
{
	platforms[i] rotateYaw( 360, 2 ); //each platform rotates individually
}

 
 
I feel like this is worded really badly and is a bit brief so I'm ready to answer questions, just post them below or PM me and I'll get round to helping you out.

1

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  
Followers 0