Challenges enable social and competitive experiences by allowing players to compete in time-bound events with friends. Learn more in the Challenges concept guide.
constinviteRequest=newChallengeInviteRequest();inviteRequest.challenge_id="CHALLENGE_123";inviteRequest.invitees=["player4"];constchallenge=awaithiro.challengeInvite(session,inviteRequest);console.log(`Invited to challenge: ${challenge.id}`);
constsubmitScoreRequest=newChallengeSubmitScoreRequest();submitScoreRequest.challenge_id="CHALLENGE_123";submitScoreRequest.setScoreNumeric(1500);submitScoreRequest.setSubscoreNumeric(0);submitScoreRequest.metadata='{"lap_times":[120]}';constchallenge=awaithiro.challengeSubmitScore(session,submitScoreRequest);console.log(`Score submitted to challenge: ${challenge.id}`);
// Join an open challenge
constjoinRequest=newChallengeJoinRequest();joinRequest.challenge_id="CHALLENGE_456";constchallenge=awaithiro.challengeJoin(session,joinRequest);console.log(`Joined challenge: ${challenge.id}`);// Leave a challenge
constleaveRequest=newChallengeLeaveRequest();leaveRequest.challenge_id="CHALLENGE_456";constchallenge=awaithiro.challengeLeave(session,leaveRequest);console.log(`Left challenge: ${challenge.id}`);
constclaimRequest=newChallengeClaimRequest();claimRequest.challenge_id="CHALLENGE_123";constchallenge=awaithiro.challengeClaim(session,claimRequest);console.log(`Claimed reward for challenge: ${challenge.id}`);