+ u/puzzle_player: Score 7/10 · Solved in 22 seconds +
+
+ Score 7/10 · Solved in 22 seconds
+
+ {postedMessage}
+
runAs: 'USER'.
+- 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 comment.id 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 SUBMIT_COMMENT 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.
diff --git a/sidebars.ts b/sidebars.ts
index 77fa6a58f..eac1d8f6a 100644
--- a/sidebars.ts
+++ b/sidebars.ts
@@ -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",
],
diff --git a/src/components/GameScoreCommentDemo/index.tsx b/src/components/GameScoreCommentDemo/index.tsx
new file mode 100644
index 000000000..57646ffef
--- /dev/null
+++ b/src/components/GameScoreCommentDemo/index.tsx
@@ -0,0 +1,270 @@
+import React, { useState } from "react";
+
+import styles from "./styles.module.css";
+
+type Example = "incorrect" | "recommended" | "optional";
+
+const examples: Array<{ id: Example; label: string }> = [
+ { id: "incorrect", label: "Top-Level App Comment" },
+ { id: "recommended", label: "Pinned Comment Reply" },
+ { id: "optional", label: "Optional Player Comment" },
+];
+
+export default function GameScoreCommentDemo(): React.ReactElement {
+ const [activeExample, setActiveExample] = useState+ {isIncorrect + ? "The app account posts a generic score as a top-level comment." + : isOptional + ? "Recommended: add a message to post at the top level, or leave it blank to reply under the pinned prompt." + : "Recommended: the player chooses to reply to the pinned prompt."} +
+ + {isOptional ? ( ++ u/puzzle_player: Score 7/10 · Solved in 22 seconds +
+
+ Score 7/10 · Solved in 22 seconds
+
+ {postedMessage}
+
+ Your score: 7/10 · Solved in 22 seconds +
+ ++ {routeHint} +
++ Reply with your score after you finish today's puzzle. +
++ Score 7/10 · Solved in 22 seconds +
++ Play a quick game right in the feed. Scroll down to keep browsing. +
+ > ); } function PostFooter({ comments, votes }: { comments: string; votes: string }) { return ( -runAs: 'USER'.
+- 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 comment.id 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 SUBMIT_COMMENT 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.
diff --git a/versioned_sidebars/version-0.15-sidebars.json b/versioned_sidebars/version-0.15-sidebars.json
index 726203d92..c0a823b77 100644
--- a/versioned_sidebars/version-0.15-sidebars.json
+++ b/versioned_sidebars/version-0.15-sidebars.json
@@ -301,6 +301,7 @@
"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"
]