lolomap / godot-console

Simple in-game console for Godot 4.x

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Godot-Console

Simple in-game console for Godot 4.x.

Features

  • Installed as plugin.
  • The Console is Singleton.
  • History of entered commands.
  • Autocomplete commands.
  • Static typing.

Installation:

  1. Clone this repository to addons folder.
  2. Enabled Godot Console in Plugins.
  3. Add ConsoleContainer node to the scene.
  4. Profit.

Usage:

Create console command:

# player.gd
func teleport(x: float, y: float) -> void:
	self.position = Vector2(x, y)

func _ready() -> void:
	Console.create_command("tp", self.teleport, "Teleport the player.")

Static typing:

With static typing, Console will try to cast arguments to a supported type.

# Arguments are float.
func teleport(x: float, y: float) -> void:
	self.position = Vector2(x, y)

Dynamic typing:

With dynamic typing, Console will NOT cast arguments to type, and arguments will be a String.

# Arguments are Strings.
func teleport(x, y):
	# Convert arguments to float.
	self.position = Vector2(x.to_float(), y.to_float())

Optional return string for print result to the console.

func add_money(value: int) -> String:
	self.money += value
	# Prints: Player money:42
	return "Player money:%d" % money

C# Bindings:

You can add 'addons/godot-console/scripts/ConsoleMono.cs' to Autoloads after 'Console'.

public partial class test : Node
{

	private void Foo(string a, string b)
	{
		ConsoleMono.Print(a + " " + b);
	}
	private static void Bar(string a, string b)
	{
		ConsoleMono.Print(b + " " + a);
	}

	public override void _Ready()
	{
		base._Ready();

        	ConsoleMono.CreateCommand("foo", Foo); //You can pass method directly as delegate
        	ConsoleMono.CreateCommand("foo2", this, MethodName.Foo); // Or you can pass target object and method name
		//ConsoleMono.CreateCommand("bar", Bar); //Exception: method is static
	}
}

License

Copyright (c) 2020-2022 Mansur Isaev and contributors

Unless otherwise specified, files in this repository are licensed under the MIT license. See LICENSE.md for more information.

About

Simple in-game console for Godot 4.x

License:MIT License


Languages

Language:GDScript 93.9%Language:C# 6.1%