You are viewing an older version of the site. Click here to view
the latest version of this page. (This may be a dead link, if so, try the root page of the docs
here.)
== ptellraw ==
Copy Code
The output might be:
Copy Code
The output might be:
Copy Code
The output might be:
A thin wrapper around the tellraw command from player context, this simply passes the input to the command. The raw is passed in as a normal (possibly associative) array, and json encoded. No validation is done on the input, so the command may fail. If not provided, the selector defaults to @s. Do not use double quotes (smart string) when providing the selector. See {{function|tellraw}} if you don't need player context.
=== Vital Info ===
{| style="width: 40%;" cellspacing="1" cellpadding="1" border="1" class="wikitable"
|-
! scope="col" width="20%" |
! scope="col" width="80%" |
|-
! scope="row" | Name
| ptellraw
|-
! scope="row" | Returns
| void
|-
! scope="row" | Usages
| [string selector], array raw
|-
! scope="row" | Throws
| [[../objects/ms.lang.CastException|ms.lang.CastException]]
|-
! scope="row" | Since
| 3.3.4
|-
! scope="row" | Restricted
| Yes
|-
! scope="row" | Optimizations
| None
|}The specification of the array may change from version to version of Minecraft, but is documented here https://minecraft.gamepedia.com/Commands#Raw_JSON_text. This function is simply written in terms of json_encode and sudo, and is otherwise equivalent to sudo('/minecraft:tellraw ' . @selector . ' ' . json_encode(@raw))
=== Usages ===
ptellraw([string selector], array raw)=== Examples === ====Example 1==== Simple usage with a plain message Given the following code:
ptellraw('@a', array('text': 'Hello World!'));

1 {{function|ptellraw}}('@a', {{function|array}}('text': 'Hello World!'));
<<Would output the plain message to all player.>>====Example 2==== Advanced usage with embedded selectors. Given the following code:
ptellraw('@a', array(
array('selector': '@s'), // prints current player
array('text': ': Hello '),
array('selector': '@p') // prints receiving player
));

1 {{function|ptellraw}}('@a', {{function|array}}(
2 {{function|array}}('selector': '@s'), // prints current player
3
4 {{function|array}}('text': ': Hello '),
5 {{function|array}}('selector': '@p') // prints receiving player
6
7 ));
<<Would output a message from the current player to all players.>>====Example 3==== Complex object Given the following code:
ptellraw(array(
array('text': 'Hello '),
array('text': 'World', 'color': 'light_purple'),
array('text': '!')
));

1 {{function|ptellraw}}({{function|array}}(
2 {{function|array}}('text': 'Hello '),
3 {{function|array}}('text': 'World', 'color': 'light_purple'),
4 {{function|array}}('text': '!')
5 ));
<<Would output the colorful message to the current player>>===See Also===
[[API/functions/tellraw.html|tellraw]]
Find a bug in this page? Edit this page yourself, then submit a pull request. (Note this page is automatically generated from the documentation in the source code.)