Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions docs/guides/best-practices/game-score-comments.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import GameScoreCommentDemo from "@site/src/components/GameScoreCommentDemo";

# Commenting Game Scores

Players may want to share game scores, but repeated score-only comments can
crowd the conversation. Keep generic score updates in one pinned thread and make
sharing an explicit player choice. Submitting on the player's behalf also lets
them report or delete their comment.

## Score comment examples

Compare a score-only reply, a score with optional player commentary, and a
rejected top-level comment from the app account.

<GameScoreCommentDemo />

In the **Optional player comment** tab, leave the field blank or add a message,
then select **Post comment** to preview where the score appears.

## What gets rejected

A game score-comment flow will be rejected when it:

- Posts a score automatically when a game starts, ends, or reaches a milestone.
- Posts the score from the app account instead of the logged-in player.
- Posts a score-only comment at the top level instead of replying to one
stickied comment.
- Combines commenting with another action, such as **Play again**, **Continue**,
or **Subscribe**.
- Requires a comment to keep playing or unlock a feature.

## What is acceptable

For a score-only comment:

- Show a separate **Comment my score** or **Post comment** action.
- Submit the comment only after the player selects that action.
- Submit it on behalf of the player with <code>runAs: 'USER'</code>.
- Reply to one stickied comment on the game post.

If the player adds their own message, the comment may be posted at the top
level. If the optional field is blank, the comment is score-only and must be a
reply to the pinned prompt. In either case, the player must choose to post it
and it must be submitted on their behalf.

## How to fix it

Create one prompt comment per game post, then use it as the parent for score-only
replies.

#### Don’t

Post a score automatically as the app account when the game ends:

~~~ts
import { reddit } from '@devvit/web/server';

async function onGameEnded(postId: string, score: number) {
await reddit.submitComment({
id: postId,
text: 'Score: ' + score,
runAs: 'APP',
});
}
~~~

This runs without the player's choice and creates a top-level comment from the
app account.

#### Do

Create and pin one prompt comment on the game post:

~~~ts
import { reddit } from '@devvit/web/server';

const comment = await reddit.submitComment({
id: postId,
text: 'Reply here with your score after you finish the game.',
runAs: 'APP',
});

await comment.distinguish(true); // distinguish + sticky to the top of the thread
~~~

Use the returned <code>comment.id</code> as the parent ID for score-only replies.
Call the following handler only after the player selects **Post comment**. When
the player entered a message, post at the top level; when the field is blank,
reply to the pinned prompt:

~~~ts
import { reddit } from '@devvit/web/server';

async function onPostScoreClick(
postId: string,
pinnedCommentId: string,
score: number,
customMessage: string,
) {
const message = customMessage.trim();
const text = message
? 'Score: ' + score + '\n\n' + message
: 'Score: ' + score;

await reddit.submitComment({
id: message ? postId : pinnedCommentId,
text,
runAs: 'USER',
});
}
~~~

Enable the <code>SUBMIT_COMMENT</code> permission. See the [User Actions
requirements](../../capabilities/server/userActions#requirements) and [game
score guidance](../../capabilities/server/userActions#adding-user-actions-to-games).
For API details, see [submitComment](../../api/redditapi/RedditClient/classes/RedditClient.md#submitcomment)
and [distinguish](../../api/redditapi/models/classes/Comment.md#distinguish).

## Review checklist

Before submitting, test both outcomes in a real post:

- Submit with the optional field blank; the score should appear under the pinned
prompt as a reply.
- Add a custom message and submit; the comment should appear at the top level
under the player's username.
- Confirm the player can finish without commenting and the comment action is
separate from other game actions.
1 change: 1 addition & 0 deletions sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ const sidebars: SidebarsConfig = {
items: [
"guides/best-practices/community_games",
"guides/best-practices/scroll-traps",
"guides/best-practices/game-score-comments",
"guides/best-practices/mod_resources",
"capabilities/server/text_fallback",
],
Expand Down
Loading
Loading