Skip to content

Commit

Permalink
Standardize all "Prints" comments in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickeon committed Dec 14, 2024
1 parent dc5f1b7 commit 1fb50ad
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 97 deletions.
58 changes: 29 additions & 29 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@
Returns a human-readable name for the given [enum Error] code.
[codeblock]
print(OK) # Prints 0
print(error_string(OK)) # Prints OK
print(error_string(ERR_BUSY)) # Prints Busy
print(error_string(ERR_OUT_OF_MEMORY)) # Prints Out of memory
print(error_string(OK)) # Prints "OK"
print(error_string(ERR_BUSY)) # Prints "Busy"
print(error_string(ERR_OUT_OF_MEMORY)) # Prints "Out of memory"
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -495,23 +495,23 @@
Returns the [Object] that corresponds to [param instance_id]. All Objects have a unique instance ID. See also [method Object.get_instance_id].
[codeblocks]
[gdscript]
var foo = "bar"
var drink = "water"

func _ready():
var id = get_instance_id()
var inst = instance_from_id(id)
print(inst.foo) # Prints bar
var instance = instance_from_id(id)
print(instance.foo) # Prints "water"
[/gdscript]
[csharp]
public partial class MyNode : Node
{
public string Foo { get; set; } = "bar";
public string Drink { get; set; } = "water";

public override void _Ready()
{
ulong id = GetInstanceId();
var inst = (MyNode)InstanceFromId(Id);
GD.Print(inst.Foo); // Prints bar
var instance = (MyNode)InstanceFromId(Id);
GD.Print(instance.Drink); // Prints "water"
}
}
[/csharp]
Expand Down Expand Up @@ -849,11 +849,11 @@
[codeblocks]
[gdscript]
var a = [1, 2, 3]
print("a", "b", a) # Prints ab[1, 2, 3]
print("a", "b", a) # Prints "ab[1, 2, 3]"
[/gdscript]
[csharp]
var a = new Godot.Collections.Array { 1, 2, 3 };
GD.Print("a", "b", a); // Prints ab[1, 2, 3]
GD.Print("a", "b", a); // Prints "ab[1, 2, 3]"
[/csharp]
[/codeblocks]
[b]Note:[/b] Consider using [method push_error] and [method push_warning] to print error and warning messages instead of [method print] or [method print_rich]. This distinguishes them from print messages used for debugging purposes, while also displaying a stack trace when an error or warning is printed. See also [member Engine.print_to_stdout] and [member ProjectSettings.application/run/disable_stdout].
Expand All @@ -867,10 +867,10 @@
When printing to standard output, the supported subset of BBCode is converted to ANSI escape codes for the terminal emulator to display. Support for ANSI escape codes varies across terminal emulators, especially for italic and strikethrough. In standard output, [code]code[/code] is represented with faint text but without any font change. Unsupported tags are left as-is in standard output.
[codeblocks]
[gdscript skip-lint]
print_rich("[color=green][b]Hello world![/b][/color]") # Prints out "Hello world!" in green with a bold font
print_rich("[color=green][b]Hello world![/b][/color]") # Prints "Hello world!", in green with a bold font.
[/gdscript]
[csharp skip-lint]
GD.PrintRich("[color=green][b]Hello world![/b][/color]"); // Prints out "Hello world!" in green with a bold font
GD.PrintRich("[color=green][b]Hello world![/b][/color]"); // Prints "Hello world!", in green with a bold font.
[/csharp]
[/codeblocks]
[b]Note:[/b] Consider using [method push_error] and [method push_warning] to print error and warning messages instead of [method print] or [method print_rich]. This distinguishes them from print messages used for debugging purposes, while also displaying a stack trace when an error or warning is printed.
Expand Down Expand Up @@ -902,16 +902,16 @@
[b]Note:[/b] The OS terminal is [i]not[/i] the same as the editor's Output dock. The output sent to the OS terminal can be seen when running Godot from a terminal. On Windows, this requires using the [code]console.exe[/code] executable.
[codeblocks]
[gdscript]
# Prints "ABC" to terminal.
printraw("A")
printraw("B")
printraw("C")
# Prints ABC to terminal
[/gdscript]
[csharp]
// Prints "ABC" to terminal.
GD.PrintRaw("A");
GD.PrintRaw("B");
GD.PrintRaw("C");
// Prints ABC to terminal
[/csharp]
[/codeblocks]
</description>
Expand All @@ -921,10 +921,10 @@
Prints one or more arguments to the console with a space between each argument.
[codeblocks]
[gdscript]
prints("A", "B", "C") # Prints A B C
prints("A", "B", "C") # Prints "A B C"
[/gdscript]
[csharp]
GD.PrintS("A", "B", "C"); // Prints A B C
GD.PrintS("A", "B", "C"); // Prints "A B C"
[/csharp]
[/codeblocks]
</description>
Expand All @@ -934,10 +934,10 @@
Prints one or more arguments to the console with a tab between each argument.
[codeblocks]
[gdscript]
printt("A", "B", "C") # Prints A B C
printt("A", "B", "C") # Prints "A B C"
[/gdscript]
[csharp]
GD.PrintT("A", "B", "C"); // Prints A B C
GD.PrintT("A", "B", "C"); // Prints "A B C"
[/csharp]
[/codeblocks]
</description>
Expand All @@ -947,10 +947,10 @@
Pushes an error message to Godot's built-in debugger and to the OS terminal.
[codeblocks]
[gdscript]
push_error("test error") # Prints "test error" to debugger and terminal as error call
push_error("test error") # Prints "test error" to debugger and terminal as an error.
[/gdscript]
[csharp]
GD.PushError("test error"); // Prints "test error" to debugger and terminal as error call
GD.PushError("test error"); // Prints "test error" to debugger and terminal as an error.
[/csharp]
[/codeblocks]
[b]Note:[/b] This function does not pause project execution. To print an error message and pause project execution in debug builds, use [code]assert(false, "test error")[/code] instead.
Expand All @@ -961,10 +961,10 @@
Pushes a warning message to Godot's built-in debugger and to the OS terminal.
[codeblocks]
[gdscript]
push_warning("test warning") # Prints "test warning" to debugger and terminal as warning call
push_warning("test warning") # Prints "test warning" to debugger and terminal as a warning.
[/gdscript]
[csharp]
GD.PushWarning("test warning"); // Prints "test warning" to debugger and terminal as warning call
GD.PushWarning("test warning"); // Prints "test warning" to debugger and terminal as a warning.
[/csharp]
[/codeblocks]
</description>
Expand Down Expand Up @@ -1402,9 +1402,9 @@
<description>
Returns a human-readable name of the given [param type], using the [enum Variant.Type] values.
[codeblock]
print(TYPE_INT) # Prints 2.
print(type_string(TYPE_INT)) # Prints "int".
print(type_string(TYPE_STRING)) # Prints "String".
print(TYPE_INT) # Prints 2
print(type_string(TYPE_INT)) # Prints "int"
print(type_string(TYPE_STRING)) # Prints "String"
[/codeblock]
See also [method typeof].
</description>
Expand All @@ -1418,10 +1418,10 @@
var json = JSON.new()
json.parse('["a", "b", "c"]')
var result = json.get_data()
if typeof(result) == TYPE_ARRAY:
print(result[0]) # Prints a
if result is Array:
print(result[0]) # Prints "a"
else:
print("Unexpected result")
print("Unexpected result!")
[/codeblock]
See also [method type_string].
</description>
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/AStarGrid2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
astarGrid.Region = new Rect2I(0, 0, 32, 32);
astarGrid.CellSize = new Vector2I(16, 16);
astarGrid.Update();
GD.Print(astarGrid.GetIdPath(Vector2I.Zero, new Vector2I(3, 4))); // prints (0, 0), (1, 1), (2, 2), (3, 3), (3, 4)
GD.Print(astarGrid.GetPointPath(Vector2I.Zero, new Vector2I(3, 4))); // prints (0, 0), (16, 16), (32, 32), (48, 48), (48, 64)
GD.Print(astarGrid.GetIdPath(Vector2I.Zero, new Vector2I(3, 4))); // Prints [(0, 0), (1, 1), (2, 2), (3, 3), (3, 4)]
GD.Print(astarGrid.GetPointPath(Vector2I.Zero, new Vector2I(3, 4))); // Prints [(0, 0), (16, 16), (32, 32), (48, 48), (48, 64)]
[/csharp]
[/codeblocks]
To remove a point from the pathfinding grid, it must be set as "solid" with [method set_point_solid].
Expand Down
10 changes: 5 additions & 5 deletions doc/classes/Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
return number % 2 == 0

func _ready():
print([1, 3, 4, 7].find_custom(is_even.bind())) # prints 2
print([1, 3, 4, 7].find_custom(is_even.bind())) # Prints 2
[/gdscript]
[/codeblocks]
</description>
Expand Down Expand Up @@ -637,10 +637,10 @@
If [method max] is not desirable, this method may also be used to implement a custom comparator:
[codeblock]
func _ready():
var arr = [Vector2(5, 0), Vector2(3, 4), Vector2(1, 2)]
var arr = [Vector2i(5, 0), Vector2i(3, 4), Vector2i(1, 2)]

var longest_vec = arr.reduce(func(max, vec): return vec if is_length_greater(vec, max) else max)
print(longest_vec) # Prints Vector2(3, 4).
print(longest_vec) # Prints (3, 4)

func is_length_greater(a, b):
return a.length() &gt; b.length()
Expand All @@ -652,11 +652,11 @@

func _ready():
var arr = [1, 2, 3, 4, 5]
# Increment count if it's even, else leaves count the same.
# If the current element is even, increment count, otherwise leave count the same.
var even_count = arr.reduce(func(count, next): return count + 1 if is_even(next) else count, 0)
print(even_count) # Prints 2
[/codeblock]
See also [method map], [method filter], [method any] and [method all].
See also [method map], [method filter], [method any], and [method all].
</description>
</method>
<method name="remove_at">
Expand Down
6 changes: 3 additions & 3 deletions doc/classes/Callable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
func test():
var callable = Callable(self, "print_args")
callable.call("hello", "world") # Prints "hello world ".
callable.call(Vector2.UP, 42, callable) # Prints "(0.0, -1.0) 42 Node(node.gd)::print_args".
callable.call(Vector2.UP, 42, callable) # Prints "(0.0, -1.0) 42 Node(node.gd)::print_args"
callable.call("invalid") # Invalid call, should have at least 2 arguments.
[/gdscript]
[csharp]
Expand All @@ -28,7 +28,7 @@
// Invalid calls fail silently.
Callable callable = new Callable(this, MethodName.PrintArgs);
callable.Call("hello", "world"); // Default parameter values are not supported, should have 3 arguments.
callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.cs)::PrintArgs".
callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.cs)::PrintArgs"
callable.Call("invalid"); // Invalid call, should have 3 arguments.
}
[/csharp]
Expand All @@ -39,7 +39,7 @@
var my_lambda = func (message):
print(message)

# Prints Hello everyone!
# Prints "Hello everyone!"
my_lambda.call("Hello everyone!")

# Prints "Attack!", when the button_pressed signal is emitted.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/JSON.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if error == OK:
var data_received = json.data
if typeof(data_received) == TYPE_ARRAY:
print(data_received) # Prints array
print(data_received) # Prints the array.
else:
print("Unexpected data")
else:
Expand Down
8 changes: 5 additions & 3 deletions doc/classes/JavaScriptObject.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

func _init():
var buf = JavaScriptBridge.create_object("ArrayBuffer", 10) # new ArrayBuffer(10)
print(buf) # prints [JavaScriptObject:OBJECT_ID]
print(buf) # Prints [JavaScriptObject:OBJECT_ID]
var uint8arr = JavaScriptBridge.create_object("Uint8Array", buf) # new Uint8Array(buf)
uint8arr[1] = 255
prints(uint8arr[1], uint8arr.byteLength) # prints 255 10
console.log(uint8arr) # prints in browser console "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]"
prints(uint8arr[1], uint8arr.byteLength) # Prints "255 10"

# Prints "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]" in the browser's console.
console.log(uint8arr)

# Equivalent of JavaScriptBridge: Array.from(uint8arr).forEach(myCallback)
JavaScriptBridge.get_interface("Array").from(uint8arr).forEach(_my_js_callback)
Expand Down
26 changes: 13 additions & 13 deletions doc/classes/NodePath.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

// propertyPath points to the "position" in the "x" axis of this node.
NodePath propertyPath = nodePath.GetAsPropertyPath();
GD.Print(propertyPath); // Prints ":position:x".
GD.Print(propertyPath); // Prints ":position:x"
[/csharp]
[/codeblocks]
</description>
Expand All @@ -118,11 +118,11 @@
[codeblocks]
[gdscript]
var node_path = ^"Sprite2D:texture:resource_name"
print(node_path.get_concatenated_subnames()) # Prints "texture:resource_name".
print(node_path.get_concatenated_subnames()) # Prints "texture:resource_name"
[/gdscript]
[csharp]
var nodePath = new NodePath("Sprite2D:texture:resource_name");
GD.Print(nodePath.GetConcatenatedSubnames()); // Prints "texture:resource_name".
GD.Print(nodePath.GetConcatenatedSubnames()); // Prints "texture:resource_name"
[/csharp]
[/codeblocks]
</description>
Expand All @@ -135,15 +135,15 @@
[codeblocks]
[gdscript]
var sprite_path = NodePath("../RigidBody2D/Sprite2D")
print(sprite_path.get_name(0)) # Prints "..".
print(sprite_path.get_name(1)) # Prints "RigidBody2D".
print(sprite_path.get_name(2)) # Prints "Sprite".
print(sprite_path.get_name(0)) # Prints ".."
print(sprite_path.get_name(1)) # Prints "RigidBody2D"
print(sprite_path.get_name(2)) # Prints "Sprite"
[/gdscript]
[csharp]
var spritePath = new NodePath("../RigidBody2D/Sprite2D");
GD.Print(spritePath.GetName(0)); // Prints "..".
GD.Print(spritePath.GetName(1)); // Prints "PathFollow2D".
GD.Print(spritePath.GetName(2)); // Prints "Sprite".
GD.Print(spritePath.GetName(0)); // Prints ".."
GD.Print(spritePath.GetName(1)); // Prints "PathFollow2D"
GD.Print(spritePath.GetName(2)); // Prints "Sprite"
[/csharp]
[/codeblocks]
</description>
Expand All @@ -163,13 +163,13 @@
[codeblocks]
[gdscript]
var path_to_name = NodePath("Sprite2D:texture:resource_name")
print(path_to_name.get_subname(0)) # Prints "texture".
print(path_to_name.get_subname(1)) # Prints "resource_name".
print(path_to_name.get_subname(0)) # Prints "texture"
print(path_to_name.get_subname(1)) # Prints "resource_name"
[/gdscript]
[csharp]
var pathToName = new NodePath("Sprite2D:texture:resource_name");
GD.Print(pathToName.GetSubname(0)); // Prints "texture".
GD.Print(pathToName.GetSubname(1)); // Prints "resource_name".
GD.Print(pathToName.GetSubname(0)); // Prints "texture"
GD.Print(pathToName.GetSubname(1)); // Prints "resource_name"
[/csharp]
[/codeblocks]
</description>
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/PackedByteArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@
[codeblocks]
[gdscript]
var array = PackedByteArray([11, 46, 255])
print(array.hex_encode()) # Prints: 0b2eff
print(array.hex_encode()) # Prints "0b2eff"
[/gdscript]
[csharp]
var array = new byte[] {11, 46, 255};
GD.Print(array.HexEncode()); // Prints: 0b2eff
GD.Print(array.HexEncode()); // Prints "0b2eff"
[/csharp]
[/codeblocks]
</description>
Expand Down
11 changes: 6 additions & 5 deletions doc/classes/PackedDataContainer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
var container = load("packed_data.res")
for key in container:
prints(key, container[key])

# Prints:
# key value
# lock (0, 0)
# another_key 123
[/codeblock]
Prints:
[codeblock lang=text]
key value
lock (0, 0)
another_key 123
[/codeblock]
Nested containers will be packed recursively. While iterating, they will be returned as [PackedDataContainerRef].
</description>
Expand Down
23 changes: 12 additions & 11 deletions doc/classes/PackedDataContainerRef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
When packing nested containers using [PackedDataContainer], they are recursively packed into [PackedDataContainerRef] (only applies to [Array] and [Dictionary]). Their data can be retrieved the same way as from [PackedDataContainer].
[codeblock]
var packed = PackedDataContainer.new()
packed.pack([1, 2, 3, ["abc", "def"], 4, 5, 6])
packed.pack([1, 2, 3, ["nested1", "nested2"], 4, 5, 6])

for element in packed:
if element is PackedDataContainerRef:
for subelement in element:
print("::", subelement)
else:
print(element)

# Prints:
# 1
# 2
# 3
# ::abc
# ::def
# 4
# 5
# 6
[/codeblock]
Prints:
[codeblock lang=text]
1
2
3
::nested1
::nested2
4
5
6
[/codeblock]
</description>
<tutorials>
Expand Down
Loading

0 comments on commit 1fb50ad

Please sign in to comment.