| Author |
Topic: Variables and level.xenon problems |
| KillerGuy790831 |
General Member Since: Aug 29, 2012 Posts: 10 Last: Sep 22, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Wednesday, Aug. 29, 2012 12:55 pm |
 |
Hi all, guys! Mind if I ask a pile of questions please?)
1). How are variables defined? Searched the scripts out and didn't actually find anything like this:
Code:
int variable_name;
2). What is for(;;) ? It doesn't actually seem to be an endless cycle... By the way, why is (;;) empty? Are there any default numbers like (i = 0; i <= spawnpoint.size; i++) ?
3). Why is score set like this:
Code:
attacker.score++;
I mean, killscores are set with a cvar... And as far as I know C, variable++ = variable + 1... Why then?
4). What do level.isSplitScreen and level.xenon mean?
5). Finally: is this IW engine really based on C but C++?
P.S. Sorry, but I'm just a noob xD |
 |
|
|
| Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Wednesday, Aug. 29, 2012 01:19 pm |
 |
KillerGuy790831 writes...Quote: Hi all, guys! Mind if I ask a pile of questions please?)
1). How are variables defined? Searched the scripts out and didn't actually find anything like this:
Code:
int variable_name;
2). What is for(;;) ? It doesn't actually seem to be an endless cycle... By the way, why is (;;) empty? Are there any default numbers like (i = 0; i <= spawnpoint.size; i++) ?
3). Why is score set like this:
Code:
attacker.score++;
I mean, killscores are set with a cvar... And as far as I know C, variable++ = variable + 1... Why then?
4). What do level.isSplitScreen and level.xenon mean?
5). Finally: is this IW engine really based on C but C++?
P.S. Sorry, but I'm just a noob xD
Let's start off with some foundation statements: COD uses a hand-crafted runtime script language which is closely related to C++ but isn't exactly the same. There are fundamental differences between COD Script and C++ but then again there are very real similarities. The best way to describe COD Script is to simply say it belongs to the curly brace group of languages. That's the best way to sum it up.
COD Script was created specifically with modding in mind. The developers wanted to allow modders to created custom content without the need to give access to the source code. As such, COD creates a virtual machine in which it is the script runtime language which controls most of the game. It allows easy changes to game events without the need to constantly re-compile the main game executables.
Now, lets get to your questions:
1. Variables are defined in a number of ways in COD. I would have to write you a tutorial in order to describe them all, so the easiest way is to recommend that you look through the stock GSC files (.gsc is a proprietary file format used exclusively in Call of Duty) to find out how they are defined, and the variety of ways they are defined.
In COD Script, the use of int() is only used to turn a string into an integer, or to round up a float into an integer. It isn't really used for much else.
2. http://en.wikipedia.org/wiki/For_loop
3. attacker.score is a runtime struct - which in COD is called a SpawnStruct() - where attacker is the primary structure, and .score is a subspecies of that structure. All entities in a level (= a COD game) have the ability to be broken down into substructures like that. You can have as much as 20 substructures. After that, the game will return errors telling you you are out of available structures.
There is no way of knowing "why" the IW developers decided to use the methods they did. Only they can answer that question, and as such I doubt they ever will. Especially since the creators of the runtime language no longer work for IW/Activision.
BTW - attacker.score is never set with a cvar. I have no idea what "killscores" is, or why it is set with a cvar, but it is certainly not part of the stock game; it has nothing to do with a player's score in a stock game. Maybe it is a mod thing? Who knows?
4. level.splitscreen and level.xenon are console definitions. COD2 was the launch game for XBOX 360, and the code name/development name for the 360 was Xenon, and of course it has the ability to have splitscreens, so it was also referred to as level.splitscreen.
5. As already stated in the opening paragraph, the COD engine is closer to C++ than anything else. The engine language is pure C++, whereas the runtime scripting language is proprietary - there is nothing else which is exactly the same as the COD scripting language.
I hope that helps.
|
 |
|
|
| IzNoGoD |
General Member Since: Nov 29, 2008 Posts: 694 Last: Nov 10, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Wednesday, Aug. 29, 2012 04:14 pm |
 |
Tally writes...Quote: KillerGuy790831 writes...Quote: Hi all, guys! Mind if I ask a pile of questions please?)
1). How are variables defined? Searched the scripts out and didn't actually find anything like this:
Code:
int variable_name;
2). What is for(;;) ? It doesn't actually seem to be an endless cycle... By the way, why is (;;) empty? Are there any default numbers like (i = 0; i <= spawnpoint.size; i++) ?
3). Why is score set like this:
Code:
attacker.score++;
I mean, killscores are set with a cvar... And as far as I know C, variable++ = variable + 1... Why then?
4). What do level.isSplitScreen and level.xenon mean?
5). Finally: is this IW engine really based on C but C++?
P.S. Sorry, but I'm just a noob xD
Let's start off with some foundation statements: COD uses a hand-crafted runtime script language which is closely related to C++ but isn't exactly the same. There are fundamental differences between COD Script and C++ but then again there are very real similarities. The best way to describe COD Script is to simply say it belongs to the curly brace group of languages. That's the best way to sum it up.
COD Script was created specifically with modding in mind. The developers wanted to allow modders to created custom content without the need to give access to the source code. As such, COD creates a virtual machine in which it is the script runtime language which controls most of the game. It allows easy changes to game events without the need to constantly re-compile the main game executables.
Now, lets get to your questions:
1. Variables are defined in a number of ways in COD. I would have to write you a tutorial in order to describe them all, so the easiest way is to recommend that you look through the stock GSC files (.gsc is a proprietary file format used exclusively in Call of Duty) to find out how they are defined, and the variety of ways they are defined.
In COD Script, the use of int() is only used to turn a string into an integer, or to round up a float into an integer. It isn't really used for much else.
2. http://en.wikipedia.org/wiki/For_loop
3. attacker.score is a runtime struct - which in COD is called a SpawnStruct() - where attacker is the primary structure, and .score is a subspecies of that structure. All entities in a level (= a COD game) have the ability to be broken down into substructures like that. You can have as much as 20 substructures. After that, the game will return errors telling you you are out of available structures.
There is no way of knowing "why" the IW developers decided to use the methods they did. Only they can answer that question, and as such I doubt they ever will. Especially since the creators of the runtime language no longer work for IW/Activision.
BTW - attacker.score is never set with a cvar. I have no idea what "killscores" is, or why it is set with a cvar, but it is certainly not part of the stock game; it has nothing to do with a player's score in a stock game. Maybe it is a mod thing? Who knows?
4. level.splitscreen and level.xenon are console definitions. COD2 was the launch game for XBOX 360, and the code name/development name for the 360 was Xenon, and of course it has the ability to have splitscreens, so it was also referred to as level.splitscreen.
5. As already stated in the opening paragraph, the COD engine is closer to C++ than anything else. The engine language is pure C++, whereas the runtime scripting language is proprietary - there is nothing else which is exactly the same as the COD scripting language.
I hope that helps.
Just some clarifications:
1. Variables are not defined like the way you used to know: cod auto-declares each var at compile time itself. It is a multi-purpose var by then: you can write anything you want to it (string, int, float, arrays, entities ("pointers") etc)
2. The for(;;) is exactly the same as while(true) except that some linux servers could have a tiny bit of trouble with for(;;) although this is unconfirmed.
3. The spawnstruct() indeed spawns a structure, but players are entities. Entities are structures - sorta. But players and other entities have some pre-set values like origin etc.
4. Tally's explanation.
5. QuakeC comes pretty close though as codscript has been derived from it. Iirc, QuakeC was based on C#? (not sure) |
 |
|
|
| Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Wednesday, Aug. 29, 2012 10:45 pm |
 |
IzNoGod writes...Quote: 5. QuakeC comes pretty close though as codscript has been derived from it. Iirc, QuakeC was based on C#? (not sure)
There is no evidence that COD Script is derived from QuakeC. People have jumped to the conclusion that because the very first Call of Duty used a heavily modified Quake 3 engine, the developers must have used QuakeC as a model on which to build their scripting language. This is really very foolish, as it misses the point that the developers had the full source code. QuakeC is a modders language, for people who don't have the full source code. If you have the source code, you don't use a modders language.
Also, it might be argued that COD Script is like QuakeC because it is a runtime scirpting language which controls gameplay. However, many games use a runtime scripting language to control gameplay. QuakeC is therefore not alone in doing that. It is therefore naive to jump to the conclusion that because COD uses a runtime scripting language in such a way that one must be derived from each other.
And then there are the fundamental differences between the two languages. There are such differences that it becomes meaningless to say they are "pretty close". If we take even a cursory look at QuakeC specifications, we can see how different the two languages are:
http://www.gamers.org/dEngine/quake/spec/quake-spec34/qc-lang.htm%23QC-LFUN
1. COD Script does not use the fundamental types that QuakeC does (see here);
2. COD Script is not limited to having the 8 parameters in a function declaration that QuakeC does;
3. COD Script is not limited to handling only 1 string from a function call at a time like QuakeC is.
4. COD Script does not have to be complied into a PROGS.DAT file and run along side the game. Any mod using COD Script will not have to be compiled at all in any file format in order to make changes to gameplay.
That's only a snippet of differences between the two. The last (#4) perhaps the most telling difference between them. I could go on, and make a great long list but the above is enough.
About the only thing that QuakeC and COD Script share in common which has any real meaning is that they are both curly brace family members - just like C and C++ are. Most of the curly brace family members have characteristics which are either similar or identical, but this masks the very real differences between them, and anyone only looking at these (small) similarities is really only looking at the language in a superficial way, surface deep, so to speak.
|
 |
|
|
| KillerGuy790831 |
General Member Since: Aug 29, 2012 Posts: 10 Last: Sep 22, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Thursday, Aug. 30, 2012 04:52 am |
 |
Well, thanks to you all, guys, that was really useful information...
So, if I want to make a script for computers only, I have to write this before I begin the actual part:
Code:
if (!level.xenon && !isSplitScreen)
don't I?
And some more question: what is the main difference between self and player? I mean, is self used for spectators also?
Does while(1) mean that this cycle repeats until the map is over? |
 |
|
|
| Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Thursday, Aug. 30, 2012 05:08 am |
 |
KillerGuy790831 writes...Quote: Well, thanks to you all, guys, that was really useful information...
So, if I want to make a script for computers only, I have to write this before I begin the actual part:
Code:
if (!level.xenon && !isSplitScreen)
don't I?
And some more question: what is the main difference between self and player? I mean, is self used for spectators also?
Does while(1) mean that this cycle repeats until the map is over?
No, you don't have to tell the game you are on a PC. The game executable tells the game that.
As for player and self. Any game entity can be referred to as "self" - including a player. But player's do not have the monopoly on using self.
Once you've defined your game entity, or found it, and you thread that entity to a function where that entity is the prime operator, then the entity becomes "self".
Example:
Code: {
ent = getEntArray( "test", "targetname" );
ent thread test()
}
test()
{
for( ;; )
{
self waittill( "trigger", player );
if( isPlayer( player ) )
player iprintlnbold( "hello" );
}
}
In the example above, ent is defined as a level entity (a trigger) which has the targetname of "test". The ent trigger is then threaded to it's own function waiting for a player to trigger it.
In the test() function you will see that ent is now referred to as self, as it is the prime operator. The player who triggered self is referred to only as player.
If I now show you another example, with an additional thread, I will transpose player into self, and self from the test() function back into ent:
Code: {
ent = getEntArray( "test", "targetname" );
ent thread test()
}
test()
{
for( ;; )
{
self waittill( "trigger", player );
if( isPlayer( player ) )
player thread transpose( self );
}
}
transpose( ent )
{
for( ;; )
{
while( self isToucing( ent ) && isAlive(self ) )
{
self iprintlnBold( "hello" );
wait( 0.05 );
}
wait( 0.05 );
}
}
You will see that in the transpose() function, the "self" from the test() function is now again referred to as "ent", and it is now the player who is called "self".
|
 |
|
|
| KillerGuy790831 |
General Member Since: Aug 29, 2012 Posts: 10 Last: Sep 22, 2012 [view latest posts] |
|
|
|
|
| KillerGuy790831 |
General Member Since: Aug 29, 2012 Posts: 10 Last: Sep 22, 2012 [view latest posts] |
|
|
|
|
| Tally |
General Member Since: Apr 21, 2005 Posts: 819 Last: Oct 26, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Tuesday, Sep. 4, 2012 07:39 am |
 |
KillerGuy790831 writes...Quote: Really thanks, but the last problem is still on... Perhaps, I want to make a script for TDM that involves getting money (That's just an example!.. yet...), so I still have a problem with defining... Searched out all MP scripts and didn't find anything really interesting... Except of for(;;)... So, how are variables defined? Need to know at least one way for defining integer...
It sounds to me like your knowledge of coding is very basic. Hence, why you are struggling to understand things, and why you are confusing a loop function with a method of defining (which a for(;;) loop is not). I would advise you to read some online tutorials on how to do basic C++ coding.
For Call of Duty, look at the stock GSC files, and even look at mods. That's how I learnt - from reading stock GSC files and mods. I had no previous knowledge of any coding language. I learnt it all from trial and experimentation.
EDIT -
Looking back to your other thread about clientids, that is a perfect example of how Call of Duty defines variables:
Code: init()
{
level.clientid = 0;
level thread onPlayerConnect();
}
onPlayerConnect()
{
for(;;)
{
level waittill("connecting", player);
player.clientid = level.clientid;
level.clientid++; // Is this safe? What if a server runs for a long time and many people join/leave
}
With something like player.money, and it works the same - you use the assign operator (i.e. = ) to define how much money a player has:
Code: init()
{
level thread onPlayerConnet();
}
onPlayerConnet()
{
for( ;; )
{
level waittill( "connected", player );
player.pers["money"] = 0;
player thread onPlayerSpawned();
}
}
onPlayerSpawned()
{
self endon( "disconnect" );
for( ;; )
{
self waittill( "spawned_player" );
self thread onMoneyUpdate();
}
}
onMoneyUpdate()
{
self endon( "killed_player" );
for( ;; )
{
if( isAlive( self ) )
{
old_money = self.pers["money"];
new_money = getMoney();
if( old_money != new_money )
{
self iprintlnBold( "Your Moeny Was Increased!" );
}
}
}
}
getMoney()
{
if( self.pers["score"] >= 5 )
return 500;
else if( self.pers["score"] >= 4 )
return 400;
else if( self.pers["score"] >= 3 )
return 300;
else if( self.pers["score"] >= 2 )
return 200;
else if( self.pers["score"] >= 1 )
return 100;
return 0;
}
That's very basic: it gives 100 times a player's score, and assigns the flag self.pers["money"] to that value. That's more-or-less how COD defines a variable.
|
 |
|
|
Comments: 0
LoadoutGun Crafting to the Max.
edited on Sep. 25, 2012 06:57 pm by Morp...
|
|