A to Z Scripting: Troubleshooting

From The DarkMod Wiki
Jump to navigationJump to search

Debugging your script

If your script doesn't do what you expect it to, it can be helpful to add sys.println() at various stages in your script to print information about what's happened so far. This helps you narrow down where the problem lies.

For one, you can check whether a certain part of the script is actually running. Example:

void check_progress()		//checks whether the player has completed an objective. If yes, starts the patrol of a previously inactive AI.
{
	sys.println("Script check_progress has been called.");		//to console: the script has been called successfully

	if($player1.getObjectiveState(5) == OBJ_COMPLETE)
	{
		sys.println("Player has completed objective 5");	//to console: the condition has been fulfilled
		sys.trigger($ai_thief_1);				//start patrol of an AI that was previously sitting at a table
	}
}


You can also print variables to the console, allowing you to see if they have the values you expect at that stage of the script. Example:

void move_mover()		//moves a harmful mover towards the player as part of a trap
{
	entity func_mover	= $func_mover_1;
	vector starting_origin	= func_mover.getOrigin();
	vector target_origin	= $player1.getOrigin();

	sys.println(func_mover + " will move from " + starting_origin + " to " + target_origin);

	func_mover.time(1);
	func_mover.moveToPos(target_origin);

	sys.waitFor(func_mover);
	sys.println(func_mover + " has arrived at + " target_origin);
}


Common errors

After loading the map, screen shows only a close-up of a random texture, can't move or use the inventory

  • Reason: this happens if you just started TDM but an error prevented you from loading the map the first time, you fixed the error and tried to reload your map again.
  • Fix: load into another map or restart TDM, then try to load the map again. The fastest way is to try to load a map that hasn't been dmapped yet, since that'll abort within seconds.


"Expected ..., found ..."

  • Possible reason: forgetting a ; or to close brackets.


"... is not a type" / "... is not a name"

  • Possible reason: forgetting a ; or to close brackets.


"Unknown value..."

  • Possible reason: forgetting a $ sign when referring to a specific entity.
  • Possible reason: referring to a variable that hasn't been defined (yet). See A to Z Scripting: More scripting basics.
  • Possible reason: referring to a variable that has been defined, but within a different script ("local variable").
  • Possible reason: trying to call a script that comes after (is written below) the calling script. The engine reads from top to bottom.


"Type mismatch on parm..."

  • Possible reason: entering input into a script event's input brackets of the wrong data type, i.e. a string where a vector is expected.


"Type mismatch for..."

  • Possible reason: trying to do maths with incompatible data types, i.e. multiplying a vector by a float.


"Bad initialization for..."

  • Reason: creating a variable with an initial value that doesn't have a matching data type.


"Locals stack underflow"

  • Reason: ingame entity calls a script but doesn't pass enough input of the correct data type to the script.


"Runaway loop error"

  • Reason: using while() without building in any kind of wait() event, causing infinite repetitions per frame.


"Event Overflow. Possible Infinite Loop in Script"

  • Background: exceeding the limit of 10,000 events per frame. As of 2.08/2.09, the console should print 5 randomly chosen events and the 5 last events.
  • Possible reason: too many repetitions of a do+while() script in a single frame, i.e. found too many entities.
  • Possible reason: TDM scripting bug (past example: fire elementals interacting with doors).


Previous article