Skip to content

Tutorial Debug

Kamran Wali edited this page Nov 27, 2024 · 2 revisions

Tutorial Debug

I have added a debug feature that will help with printing debugs. For now the debug will work with nodes, scripts, resources and objects. To use the debug tool simply call COP_Debug from the script. You can read the COP_Debug document to understand it better. Let me explain the debug methods.

  1. void print_script( Object object, String message ) - This method will print the name of the script and the log message provided. If the object provided does NOT have a script or is NOT a script then the method will print an error. To use this method just call it by COP_Debug.print_script(some_script, "some_log").
  2. void print_node( Node object, String message ) - This method will print the name of the node and the log message provided. To use this method just call it by COP_Debug.print_node(some_node, "some_log").
  3. void print_resource( Resource object, String message ) - This method will print the name of the resource and the log message provided. If the object provided is NOT a resource then the method will print an error. To use this method just call it by COP_Debug.print_resource(some_resource, "some_log").
  4. void print_object( Object object, String message ) - This method will print the name of the object and the ID. To use this method just call it by COP_Dubug.print_object(some_object, "some_log").
  5. String get_script_log( Object object, String message ) - This method will return a String with the name of the script and the log message. Use this method for custom printing if needed.
  6. String get_node_log( Node object, String message ) - This method will return a String with the name of the node and the log message. Use this method for custom printing if needed.
  7. String get_resource_log( Resource object, String message ) - This method will return a String with the name of the resource and the log message. Use this method for custom printing if needed.
  8. String get_object_log( Object object, String message ) - This method will return a String with the name and ID of the object and the log message. Use this method for custom printing if neeeded.

Examples

Here are some examples for using COP_Debug tool.

Example for printing debugs.

extends Node

@export var _some_flag: COP_FixedBoolVar

func _ready() -> void:
	COP_Debug.print_script(self, "This is an attached script.")
	COP_Debug.print_node(self, "This is the node.")
	COP_Debug.print_resource(_some_flag, "This is a resource object.")
OUTPUT:
=========
***script_path.some_script.gd****
This is an attached script.
=========
some_node_name -> This is the node.
some_resource_name -> This is a resource object.

Example for printing custom debugs.

extends Node

func _ready() -> void:
	COP_Debug.print_script(self, COP_Debug.get_node_log(self, "This is the node."))
OUTPUT:
=========
***script_path.some_script.gd***
some_node_name -> This is the node
=========
Clone this wiki locally