A to Z Scripting: Troubleshooting: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
== Troubleshooting ==
== Debugging your script ==
=== 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.
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.
Line 8: Line 7:
  void check_progress() //checks whether the player has completed an objective. If yes, starts the patrol of a previously inactive AI.
  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.");
  sys.println("Script check_progress has been called."); //to console: the script has been called successfully
   
   
  if($player1.getObjectiveState(5) == OBJ_COMPLETE)
  if($player1.getObjectiveState(5) == OBJ_COMPLETE)
  {
  {
  sys.println("Player has completed objective 5");
  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
  sys.trigger($ai_thief_1); //start patrol of an AI that was previously sitting at a table
  }
  }
Line 36: Line 35:




=== Common errors ===
== Common errors & solutions==
* Problem: after loading the map, the screen shows only a close-up of a random texture, can't move or use the inventory
=== After loading the map, screen shows only a close-up of a random texture, can't move or use the inventory ===
** 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.
* '''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.
* '''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.





Revision as of 18:39, 27 December 2020

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 & solutions

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.


Previous article