How to get all playerIds under reserved status in a gamelift session Unreal Engine GAmeLIft server SDK C++.

0

Aws::GameLift::Server::Model::DescribePlayerSessionsRequest DescribePlayerSessionsRequest; DescribePlayerSessionsRequest.SetGameSessionId(TCHAR_TO_ANSI(*sessionId)); DescribePlayerSessionsRequest.SetPlayerSessionStatusFilter("RESERVED"); auto DescribePlayerSessionsOutcome = Aws::GameLift::Server::DescribePlayerSessions(DescribePlayerSessionsRequest);

From this object, How can I for loop to get player Ids? I want to get the playerIds under reserved status.

5 Answers
0

I apologize for any confusion earlier. It seems like there is an issue with the usage of iterators in your code. The errors you're encountering are related to trying to use iterators (std::begin and std::end) on an object that doesn't support them.

  • In the corrected code snippet I provided earlier, there should not be any issues with iterators. However, if you're still facing these errors, here are a few things you can check:

  • Make sure you have included the necessary headers for AWS GameLift and Unreal Engine at the top of your .cpp file.

  • Ensure that you have properly initialized the DescribePlayerSessionsOutcome object and that it's of the correct type (Aws::GameLift::Server::DescribePlayerSessionsOutcome).

  • Check if you have inadvertently shadowed any standard library functions like std::begin and std::end with your own code or macros.

  • Verify that the AWS GameLift SDK and Unreal Engine dependencies are set up correctly in your project settings.

If you are still encountering issues after verifying these points, please share the relevant portions of your code (especially the variable declarations and how you are using the AWS GameLift SDK) so that I can provide more specific assistance.

profile picture
EXPERT
answered 7 months ago
  • Hi Thanks for the continous help. But the corrected code snippet is identical to your first code snippet. Apart from you mentioning that no need to add getGameSession(), the code is the same. Can you check again to see if u missed something while adding the corrected code because I don't see any difference. If I am understanding wrong, please correct me. Thanks so much.

0

Hello.

You can try this code snippet:

#include <aws/gamelift/server/GameLiftServerAPI.h>

// Your code to set up the DescribePlayerSessionsRequest
Aws::GameLift::Server::Model::DescribePlayerSessionsRequest DescribePlayerSessionsRequest;
DescribePlayerSessionsRequest.SetGameSessionId(TCHAR_TO_ANSI(*sessionId));
DescribePlayerSessionsRequest.SetPlayerSessionStatusFilter("RESERVED");

// Call DescribePlayerSessions to get player sessions with RESERVED status
auto DescribePlayerSessionsOutcome = Aws::GameLift::Server::DescribePlayerSessions(DescribePlayerSessionsRequest);

// Check if the DescribePlayerSessions call was successful
if (DescribePlayerSessionsOutcome.IsSuccess())
{
    const auto& playerSessions = DescribePlayerSessionsOutcome.GetResult().GetPlayerSessions();

    // Iterate through the player sessions and get playerIds for RESERVED sessions
    for (const auto& playerSession : playerSessions)
    {
        if (playerSession.GetPlayerSessionStatus() == "RESERVED")
        {
            const FString playerId = FString(playerSession.GetPlayerId().c_str());
            // Use playerId as needed for processing
        }
    }
}
else
{
    // Handle the case where DescribePlayerSessions call was not successful
    UE_LOG(LogTemp, Error, TEXT("DescribePlayerSessions failed: %s"), *DescribePlayerSessionsOutcome.GetError().GetErrorMessage());
}

Best regards, Andrii

profile picture
EXPERT
answered 7 months ago
0

'Aws::GameLift::Server::Model::DescribePlayerSessionsResult::GetPlayerSessions': function does not take 0 arguments 'playerSessions': references must be initialized error C3536: 'playerSessions': cannot be used before it is initialized error C2672: 'begin': no matching overloaded function found error C2893: Failed to specialize function template 'unknown-type std::begin(_Container &)' error C2784: 'const _Elem *std::begin(std::initializer_list<_Elem>) noexcept': could not deduce template argument for 'std::initializer_list<_Elem>' from 'int' error C2672: 'end': no matching overloaded function found error C2893: Failed to specialize function template 'unknown-type std::end(_Container &)' error C2784: 'const _Elem *std::end(std::initializer_list<_Elem>) noexcept': could not deduce template argument for 'std::initializer_list<_Elem>' from 'int' error C3536: '<begin>$L0': cannot be used before it is initialized error C3536: '<end>$L0': cannot be used before it is initialized error C2100: illegal indirection

I am getting the above errors.

answered 7 months ago
0

I apologize for the confusion. It appears there was a mistake in my previous response regarding the usage of DescribePlayerSessionsResult::GetPlayerSessions. The AWS GameLift SDK does not provide a direct GetPlayerSessions method within DescribePlayerSessionsResult. Instead, you can access player sessions directly from the playerSessions variable returned by DescribePlayerSessionsOutcome.GetResult().

Here's the corrected code snippet:

#include <aws/gamelift/server/GameLiftServerAPI.h>

// Your code to set up the DescribePlayerSessionsRequest
Aws::GameLift::Server::Model::DescribePlayerSessionsRequest DescribePlayerSessionsRequest;
DescribePlayerSessionsRequest.SetGameSessionId(TCHAR_TO_ANSI(*sessionId));
DescribePlayerSessionsRequest.SetPlayerSessionStatusFilter("RESERVED");

// Call DescribePlayerSessions to get player sessions with RESERVED status
auto DescribePlayerSessionsOutcome = Aws::GameLift::Server::DescribePlayerSessions(DescribePlayerSessionsRequest);

// Check if the DescribePlayerSessions call was successful
if (DescribePlayerSessionsOutcome.IsSuccess())
{
    const auto& playerSessions = DescribePlayerSessionsOutcome.GetResult().GetPlayerSessions();

    // Iterate through the player sessions and get playerIds for RESERVED sessions
    for (const auto& playerSession : playerSessions)
    {
        if (playerSession.GetPlayerSessionStatus() == "RESERVED")
        {
            const FString playerId = FString(playerSession.GetPlayerId().c_str());
            // Use playerId as needed for processing
        }
    }
}
else
{
    // Handle the case where DescribePlayerSessions call was not successful
    UE_LOG(LogTemp, Error, TEXT("DescribePlayerSessions failed: %s"), *DescribePlayerSessionsOutcome.GetError().GetErrorMessage());
}

Best regards, Andrii

profile picture
EXPERT
answered 7 months ago
0

Thanks for the help, but Still getting error:

C:\Users\User\Documents\Source\GameModes.cpp(273): error C2672: 'begin': no matching overloaded function found UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): error C2893: Failed to specialize function template 'unknown-type std::begin(_Container &)' UATHelper: Packaging (Windows): C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\INCLUDE\xutility(1844): note: see declaration of 'std::begin' UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\.cpp(274): note: With the following template arguments: UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes\GameMode.cpp(274): note: '_Container=const R' UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): error C2784: 'const _Elem *std::begin(std::initializer_list<_Elem>) noexcept': could not deduce template argument for 'std::initializer_list<_Elem>' from 'const R' UATHelper: Packaging (Windows): with UATHelper: Packaging (Windows): [ UATHelper: Packaging (Windows): R=Aws::GameLift::Server::Model::DescribePlayerSessionsResult UATHelper: Packaging (Windows): ] UATHelper: Packaging (Windows): C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\INCLUDE\initializer_list(55): note: see declaration of 'std::begin' UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(273): error C2672: 'end': no matching overloaded function found UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): error C2893: Failed to specialize function template 'unknown-type std::end(_Container &)' UATHelper: Packaging (Windows): C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\INCLUDE\xutility(1854): note: see declaration of 'std::end' UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): note: With the following template arguments: UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): note: '_Container=const R' UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): error C2784: 'const _Elem *std::end(std::initializer_list<_Elem>) noexcept': could not deduce template argument for 'std::initializer_list<_Elem>' from 'const R' UATHelper: Packaging (Windows): with UATHelper: Packaging (Windows): [ UATHelper: Packaging (Windows): R=Aws::GameLift::Server::Model::DescribePlayerSessionsResult UATHelper: Packaging (Windows): ] UATHelper: Packaging (Windows): C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\INCLUDE\initializer_list(60): note: see declaration of 'std::end' UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): error C3536: '<begin>$L0': cannot be used before it is initialized UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(274): error C3536: '<end>$L0': cannot be used before it is initialized UATHelper: Packaging (Windows): C:\Users\User\Documents-game-new\Source\GameModes.cpp(273): error C2100: illegal indirection

answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions