Call of Duty: World at War

Call of Duty: World at War

Not enough ratings
[Scripting Tutorial] Debugging Scripts
By SparkyMcSparks
A lot of problems can be solved quite easily by debugging your own scripts to find the root of a problem. This tutorial is easy enough that you don't need much scripting knowledge, and if anything, it'll let you post valuable information when you do need to seek help from other people so they can better assist you.
 
Rate  
Favorite
Favorited
Unfavorite
Running The Game In Developer Mode
First off, you want to run some dvars when working on your map / mod. These are the ones I recommend ALWAYS using when developing your content:

+set developer 2 +set developer_script 1 +set thereisacow "1337" +set logfile 2 +devmap <mapname>
Zombies Debugging
In addition to running the game in developer mode, you can use for zombie related development tools:

+set zombie_cheat <1-5>

1
Start all players with 100000 points
2
Start all players with 100000 points don’t spawn any zombies
3
Start all players with 100000 points turn on the power after 5 seconds
4
Points no zombies power after 5 seconds
5
Same as 4 the ability to re-buy the same perk over and over. Useful for testing animations, sounds, etc.
Checking Logfile
Everything that is printed to the console is printed to the console.log file which goes in the main folder by default. If you're running a mod, the console.log will be in your mod folder within the installation directory.

If you're posting an error on the forum or for someone to fix, it's generally a good idea to attach this file since it'll contain all the console information of what went wrong like a callstack.
Script Runtime Errors
When running your map in developer mode, if you encounter a Script Runtime Error (SRE) the game will end the map if it's fatal or bring up a pop-up window if it's non-fatal.

If you have a SRE you should ALWAYS address them to get a proper fix in -- don't assume since people playing your map won't be running developer mode the issue goes away. It is still happening in the background and can cause really bad issues like hitching, unexpected script results, or even crashing your map.

They usually look like this:
******* script runtime error ******* undefined is not an array, string, or vector: (file 'maps/mp/_load.gsc', line 113) if (!isdefined(level._effect["lantern_light"])) * called from: (file 'maps/mp/_load.gsc', line 12) lanterns thread lanterns(); * called from: (file 'maps/mp/mp_houses22.gsc', line 2) maps\mp\_load::main(); * started from: (file 'maps/mp/mp_houses22.gsc', line 1) main() { * ************************************

The way it's displayed is the bottom is the origin of the script routine, and the very top is where the SRE was encountered.

In the above example, the map main() function calls the _load.gsc main() function which calls the _load.gsc lanterns() function which has an error on line 113 with the lantern FX.

Note: The asterisk (*) will always be under the variable / function with the error. It'll display properly in-game to give you a better idea what part of the line is problematic.
Assertions
Asserts are a development feature that check if a condition is true and if not, stops the game. This is useful for when you as a designer want to validate your assumptions about what the state of the game should be whenever possible.

Example:
AssertEx( IsDefined( ai_maxis), "Maxis AI did not spawn." );

These have no impact in non-developer mode, so people playing your map will never trigger them... but they may run into a SRE. In that case, you should avoid defensive coding to get around the issue and instead fix the issue; if something shouldn't happen, then an assertion is the right thing to use.

Here are the various Assert API you have at your disposal:
Assert( <value> );
Assert that the given statement is correct. The function will throw a script error if this is false.
AssertEx( <value>, <message> );
Assert that the given statement is correct. The function will throw a script error if this is false, with the given message.
AssertMsg( <message> );
Throws a script error with the given message.
Dev Blocks
If you want certain script snippets to only execute when in developer mode, you can wrap in /# #/

This is useful if you want to kick off developer functions or do prints to the screen of information you want to see from script. People playing your map won't see these.

Example:
while ( true ) { trig waittill( "trigger", who ); { /# IPrintLnBold( "Player who purchased perk: " who.playername ); #/ } }
Common SREs
could not find script <script_name_here>
You don't have the script in a FastFile or IWD that is being loaded by the map.

must be applied to an int (applied to undefined)
You're trying to do a mathematical operation on a variable that isn't defined before the operation. You can't initiate a variable while doing the mathematical operation, you need to define it earlier even if it's just a zero.

undefined is not an array, string, or vector
Variable you're trying to reference is empty.

cannot set field of removed entity
Entity has left / deleted from the game or the entity variable it was stored in has been reset / undefined.

cannot cast undefined to <variable_type_here>
You're trying to reference a variable that is empty.

potential infinite loop in script
Your while or for loop doesn't have a wait in it. Every loop needs a wait, whether it be a timed wait of 0.05 seconds or waiting for a notify.
< >
4 Comments
Artsergei Jan 6, 2017 @ 1:24pm 
And more. I loading my example map+scripts and i walking on the map and actors spawning. but CoD5 don't show any errors. )
Artsergei Jan 6, 2017 @ 1:18pm 
And it would be absolutely fantastic if you could make tutorial on the subject of dialogues and speech for actors, like any tutorial you have already written here.

And thank you for your previous tutorials.

Заранее спасибо Вам,
И Замечательного времени суток!
--------------------------------
= Sergei
Artsergei Jan 6, 2017 @ 1:18pm 
I see that you many know about GSC-scripts.
Can you help me with one script code? i want understand. Can you prompt, advise, how I can go out from problem.

I try to repeat some script for my sp-map, but now I learning one moment, moment for a question of dialogue, animation, speech, etc.

I found a guide http://wiki.modsrepository.com/index.php?title=Call_of_Duty_5:_Animation_Overview
and other facial animation on this site. And I am doing this example for me as show in the site, but my actors allies don't speak. :(( why? i don't I understand.

and more, I made for they to spawn and they should go to the place where this actors starting to communication, but they just stand in place, they eyes blinking and purses his lips and they look in different directions and this all that they doing. But there is no conversation.

How to be? You can look the link above, please? you many know about GSC-scripts.
Maybe you can help, why an actors may don't talk? May be I do something unfinished?
Schrimpscampi2 Oct 5, 2014 @ 9:13am 
Why not make a Call of duty World at war 2 for the first world war.