Skip to content

Debug Lines

Trivaxy edited this page Jun 25, 2024 · 10 revisions

When debugging functions, it's helpful to be able to print debug messages in chat to inspect and verify what your function is doing.

This is typically achievable via tellraw, but it is limited and cumbersome to use for this purpose. Datamancer introduces a feature called debug lines which allow you to write out text as a template, expand it with data dynamically, and then send the result to OP players.

Debug lines start with a #! (making them compatible with vanilla, as they won't do anything there). The rest of the line is called the debug line's template, which will be modified with the data you specify inside placeholders. When function execution reaches a debug line, it will be processed and printed to chat.

(Tip: before proceeding, check out the Templates & Placeholders page for a quick guide on them.)

Here's a basic debug line:

#! This is a debug line!

This will be printed to chat as-is. Cool, but boring:

image

Placeholders

Debug lines shine once you start using placeholders. A placeholder is a string inside your template which will expand when it is processed into another string containing the data you request.

It's best illustrated with an example:

scoreboard players set @s coins 80
#! I have {score @s coins} coins in my balance.

The above debug line has the placeholder {score @s coins}. This placeholder will retrieve the score for the specified entity and objective and substitute itself with that score. The result is this:

image

That's much more interesting.

Let's try passing in more than one entity to the score placeholder.

scoreboard players set Player1 coins 50
scoreboard players set Player2 coins 100
scoreboard players set Player3 coins 200
#! The coins everyone has are {score @e[type=player] coins}

image

Some placeholders don't have a problem with it!

You can experiment with all sorts of different placeholders. Happy debugging!

Clone this wiki locally