discord-api-docs icon indicating copy to clipboard operation
discord-api-docs copied to clipboard

SDK starter guide lacks important details

Open bugproof opened this issue 4 years ago • 2 comments

Application below will crash if discord is not running or is not installed. core will be null. The docs should mention that. (when using NoRequireDiscord)

if (core) should be added before updating activity.

https://discordapp.com/developers/docs/game-sdk/sdk-starter-guide

#include "MyPawn.h"
#include "discord-files/discord.h"

discord::Core* core{};

AMyPawn::AMyPawn()
{
     // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
}

// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
    Super::BeginPlay();
    /*
        Grab that Client ID from earlier
        Discord.CreateFlags.Default will require Discord to be running for the game to work
        If Discord is not running, it will:
        1. Close your game
        2. Open Discord
        3. Attempt to re-open your game
        Step 3 will fail when running directly from the Unity editor
        Therefore, always keep Discord running during tests, or use Discord.CreateFlags.NoRequireDiscord
    */
    auto result = discord::Core::Create(461618159171141643, DiscordCreateFlags_Default, &core);
    discord::Activity activity{};
    activity.SetState("Testing");
    activity.SetDetails("Fruit Loops");
    core->ActivityManager().UpdateActivity(activity, [](discord::Result result) {

    });
}

// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    ::core->RunCallbacks();
}

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);
}

bugproof avatar Apr 12 '20 01:04 bugproof

I've marked this as documentation needed, but pull requests are welcome.

night avatar Apr 13 '20 19:04 night

I think it also needs this for dispatch, it is not clear at all, without directly asking Mason, I would not have been able to do it, even aster scanning the docs for weeks

PixelNinja132 avatar Apr 25 '20 11:04 PixelNinja132