A to Z Scripting: Troubleshooting: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Dragofer (talk | contribs)
No edit summary
Dragofer (talk | contribs)
Line 35: Line 35:




== Common errors & solutions==
== Common errors ==
=== After loading the map, 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 ===
* '''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.
* '''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.


=== Expected [...], found [...] ===
=== Expected [...], found [...] ===
* '''Possible reason''': forgetting a ; or to close brackets
* '''Possible reason''': forgetting a ; or to close brackets


=== ... is not a type / ... is not a name ===
=== ... is not a type / ... is not a name ===
* '''Possible reason''': forgetting a ; or to close brackets
* '''Possible reason''': forgetting a ; or to close brackets


=== Unknown value ===
=== Unknown value ===
* '''Possible reason''': forgetting a $ sign when referring to a specific entity.
* '''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 basics]].
* '''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''': 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
* '''Possible reason''': trying to call a script that comes after (is written below) the calling script


=== Type mismatch on parm... ===
=== 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.
* '''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... ===
=== Type mismatch for... ===
* '''Possible reason''': trying to do maths with incompatible data types, i.e. multiplying a vector by a float.
* '''Possible reason''': trying to do maths with incompatible data types, i.e. multiplying a vector by a float.


=== Bad initialization for... ===
=== Bad initialization for... ===
* '''Reason''': creating a variable with an initial value that doesn't have a matching data type.
* '''Reason''': creating a variable with an initial value that doesn't have a matching data type.


=== Locals stack underflow ===
=== Locals stack underflow ===
* '''Reason''': ingame entity calls a script but doesn't pass enough input of the correct data type to the script.
* '''Reason''': ingame entity calls a script but doesn't pass enough input of the correct data type to the script.


== Previous article ==
== Previous article ==

Revision as of 18:59, 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

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


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.

Previous article