Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 9 Guests
Online:

LATEST FORUM THREADS

»
warfare
CoD4 Map + Mod Releases
Voting menu on maps
CoD+UO General
Hauling 911
CoDBO3 General

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked
Page
Next Page
subscribe
Author Topic: help with arrays
cybershot
General Member
Since: Dec 29, 2005
Posts: 944
Last: Mar 4, 2018
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Friday, Nov. 9, 2007 07:17 am
I am trying to understand arrays in cod2 and in cod4. i have an example here from cod4. C++ says that when you are making an array, that you define the type like

int name[5]

wich says integer, array name is name and the size is 5 meaning it's storing five values..

but in cod2 and 4 it's allways this

level.placement["allies"] = [];

or this

level.players = [];

is this just a way of stating that the array is infinate. that the value just keeps going? Can anyone explain this with as much detail as possible. thanks

edited on Nov. 9, 2007 02:18 am by cybershot
Share |
All-Killer
General Member
Since: May 26, 2006
Posts: 140
Last: Nov 23, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Friday, Nov. 9, 2007 09:16 am
An array is nothing more than giving more entity's the same targetname and change the code. If you would use getent it will give a script error because there are more enitiy's with the same targetname. But instead use getentarray and you will not have any problems.

Simle example

Code:

entity = getentarray("entity","targetname");

   for (i=0 ; i < entity.size; i++) 



edited on Nov. 9, 2007 04:18 am by All-Killer
Share |
nedgerblansky
General Member
Since: Jan 28, 2005
Posts: 57
Last: Nov 9, 2007
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Friday, Nov. 9, 2007 09:23 am
array = [];
is just an initialization of the variable array.
It tells that array is now an array and ready to accept values.

Usually array indexes are :
numbers -> array[4] = "allies";
strings -> array["allies"] = 8;

I guess you could use other objects as indexes but numbers and strings should be enough in most cases.
Share |
The_Caretaker
General Member
Since: Jun 8, 2004
Posts: 11625
Last: Jul 7, 2009
[view latest posts]
Level 10
Category: CoD2 Scripting
Posted: Friday, Nov. 9, 2007 05:31 pm
To go a bit deeper into this


In C(++) when you define an array you have to set the number of arguments which are going to be in the array, because the program reserves memory locations for this array.. by telling the program how long the array is going to be and what it will contain (int name[5]) it will know exactly how much memory to reserve.

In CoD my guess is, array=[]; reserves a spot in the memory, with a set number of arguments.. (256 or something probably.. it would be interesting to find out this number, just for fun). By not telling the game how big the array is going to be you can put stuff in it, without knowing in advance how many arguments there will be... like certain entities, triggers or players for instance.

level.players = [];

because the engine won't know in advance how many players there will be.
Share |
TexasRebel
General Member
Since: May 1, 2006
Posts: 373
Last: Aug 20, 2013
[view latest posts]
Level 5
Category: CoD2 Scripting
Posted: Friday, Nov. 9, 2007 07:07 pm
I know in C++ you can also just create a small array and if need be add more memory "slots" to it or take those you dont need away. Im curious if COD does this automatically if the default number is 256 and you do not use them all up.
Share |
cybershot
General Member
Since: Dec 29, 2005
Posts: 944
Last: Mar 4, 2018
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Saturday, Nov. 10, 2007 01:44 am
wow. that was some good answers. thanks guys. Is there any small functions anyone knows of that contains an array that we can examine, or tear apart to give a greater explanation of how the array is working in the game. especially how it functions with loops.
So Caretaker, how would we find out what the size of the array is just for fun. It must be hard coded into the game then huh?
Share |
hansgrubber
General Member
Since: Aug 7, 2004
Posts: 196
Last: Jul 6, 2009
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Saturday, Nov. 10, 2007 03:15 am
Just to throw a monkey wrench in, there is also a dynamic
array that adjusts it size on fly.
Quote:
I know in C++ you can also just create a small array and if need be add more memory "slots" to it or take those you dont need away. Im curious if COD does this automatically if the default number is 256 and you do not use them all up.
That would actually be poor programing, and a waste of memoryto use a huge array and not use all of its size.

edited on Nov. 9, 2007 10:20 pm by hansgrubber
Share |
cybershot
General Member
Since: Dec 29, 2005
Posts: 944
Last: Mar 4, 2018
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Saturday, Nov. 10, 2007 03:55 am
howabout you provide an example of this dynamic array
Share |
The_Caretaker
General Member
Since: Jun 8, 2004
Posts: 11625
Last: Jul 7, 2009
[view latest posts]
Level 10
Category: CoD2 Scripting
Posted: Saturday, Nov. 10, 2007 09:01 am
Quote:
So Caretaker, how would we find out what the size of the array is just for fun. It must be hard coded into the game then huh?


From the top of my head.. try something like this:

Code:
array=[];
for (k=0;k<2048;k++
{
array[k]=k;
iprintln (k);
wait 0.2;
}


this should fill the array with a new number every 0.2 seconds and print it on screen.. up to 2048... if the array is full, the game will probably crash :p
If not, raise the number and run again..
Share |
hansgrubber
General Member
Since: Aug 7, 2004
Posts: 196
Last: Jul 6, 2009
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Saturday, Nov. 10, 2007 01:55 pm
Actually in C++ now, whenever you declare a array and don't give it a size it is a dynamic array. So right here he declares a array "array" of no size!

array=[];
Share |
Restricted Access Topic is Locked
Page
Next Page
subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»