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

Members Online

»
0 Active | 98 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

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 subscribe
Author Topic: Advanced Programming In Cod2
r00t_
General Member
Since: Dec 15, 2010
Posts: 51
Last: May 16, 2011
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Friday, Feb. 4, 2011 02:28 am
I am currently trying to convert a C/C++ header file into a usable cod2 script. It's not like the entire header file, just a function that is very important for what I am trying to accomplish. What you've probably come to expect is that while i'm trying to convert this file, I've come across some problems. Most of the problems I have overcome without a problem. But I need to know what to do with this.
Code:
pathBank[pathfinderID] = (int*) realloc (pathBank[pathfinderID], pathLength[pathfinderID]*8);

It's the realloc function that I'm having trouble with. I believe it reallocate a memory block. First of all, I need to know if this is necessary at all for a cod2 script, and if it is, I need to know how to convert it to something cod2 can handle.
Thanks
Share |
tHMatt
General Member
Since: Sep 11, 2007
Posts: 473
Last: Mar 20, 2013
[view latest posts]
Level 5
Category: CoD2 Scripting
Posted: Friday, Feb. 4, 2011 02:34 am
you can use pointers in cod2?!
Share |
r00t_
General Member
Since: Dec 15, 2010
Posts: 51
Last: May 16, 2011
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Friday, Feb. 4, 2011 03:17 am
That my question. I have no idea! If not, I'm going to have to figure out to use pointers, just so that I'll be able to take them all out of the original function. Anyone have any ideas how I can do this?
Share |
tHMatt
General Member
Since: Sep 11, 2007
Posts: 473
Last: Mar 20, 2013
[view latest posts]
Level 5
Category: CoD2 Scripting
Posted: Friday, Feb. 4, 2011 03:55 am
I've never seen referencing(&) or dereferencing(*) used.. unless im blind and stupid(probably) in cod level you shouldnt really ever need to access memory tbh..
Share |
tomalla
General Member
Since: Jan 16, 2007
Posts: 393
Last: Jun 10, 2012
[view latest posts]
Level 5
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Friday, Feb. 4, 2011 10:06 am
You'd be surprised. There are pointers in CoD2, but as far as I know you have no power managing them at all. Pointer is automatically created when you create a structure or spawn an object ( or make a reference to the existing one by getent(), getentarray() and so on functions ). Let's suppose you have:

Code:

main()
{
	ent = getent("value", "key");
	thread func(ent);
	ent waittill("passed");
	iprintlnbold("^1Passed!");
}

func(var)
{
	wait(1);
	var notify("passed");
}


The result will be of course the big red text, shown after one second ;)

Your 'ent' variable is treated like a pointer - when it's passed down as an argument, it still refers to the same object in map ( in memory ). It doesn't copy the whole object like functions in C/C++. The only difference is you treat it like a normal variable.

Back to your code. It seems that pathBank is an array that stores the arrays of ints. That line of code might expand the capacity of one array to store more ints. In CoD2 there is no need to allocate any memory, because the arrays are already 'dynamic'. When you want to add new value at the end of an array you can use the following code:

Code:

array = [];
array[array.size] = "first value";
array[array.size] = "second value";
//...


It seems the engine automatically allocates additional memory for new elements added at the end of an array and frees it. So I guess you can go ahead and delete that line [biggrin] Cheers
Share |
r00t_
General Member
Since: Dec 15, 2010
Posts: 51
Last: May 16, 2011
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Friday, Feb. 4, 2011 04:47 pm
Thank you so much for the quick and very thought-out response. I did know that the Cod arrays were dynamic, but I was unaware that the line I referred to earlier was just resizing a pointer array. So thanks again, this has been an enormous help. [lol]
[read]
Share |
playername
Preferred Member
Since: Aug 24, 2006
Posts: 821
Last: Apr 15, 2011
[view latest posts]
Level 7
Forum Moderator
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Feb. 15, 2011 01:03 am
Haha, Call of Duty 2 scripting is simply that: scripting. Scripting basically means you should never have to mess with memory at all. That includes anything dealing with pointers, allocating memory, and releasing that memory. Scripting just allows dynamic source code without the source part! It is what makes modding possible!!!

In CoD script, ONLY objects/entities are treated as pointers automatically, everything else is copied. For example, the following would produce the unexpected outcome of "Foo Bar Code".
Code:
main() {
	temp = [];
	temp[temp.size] = "Foo";
	temp[temp.size] = "Bar";
	temp[temp.size] = "Code";

	editTempArray(temp);

	iprintln(temp[0]+" "+temp[1]+" "+temp[2]);
}

editTempArray(copiedMe) {
	copiedMe[0] = "Hello";
	copiedMe[1] = "World";
	copiedMe[2] = "!!!!!";
}


In order to get the result "Hello World !!!!!" you would have to return the edited array into temp like so:
Code:
main() {
	temp = [];
	temp[temp.size] = "Foo";
	temp[temp.size] = "Bar";
	temp[temp.size] = "Code";

	temp = editTempArray(temp);

	iprintln(temp[0]+" "+temp[1]+" "+temp[2]);
}

editTempArray(copiedMe) {
	copiedMe[0] = "Hello";
	copiedMe[1] = "World";

	return copiedMe;
}
nullFew tips for coding.
1. Keep the script as short as possible.
2. Don't comment every line. Only comment portions where they may be needed to point something out.
3. Don't over complicate the script, keep it organized and easy to read.

These help you find simple errors and makes it easy to make changes.
Share |
Restricted Access Topic is Locked 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

»