可以提供一个使用QueryIndex在GameSparks云代码中处理程序事件的工作示例吗?

0

【以下的问题经过翻译处理】 我正试图返回一个查询我的名为BattleRoyalePlayerLobbyTable的表中的大厅中的玩家列表,其中lobbyId,playerId为复合键,并且名为lobbyId-index的索引以lobbyId作为主键,使用请求消息中传递的message.lobbyId。

尝试
{
  const tableName = 'BattleRoyalePlayerLobbyTable';
  const indexName = 'lobbyId-index';
  const keyConditionExpression = '#lobbyId = :lobbyid';
  const expressionAttributeNames = {'#lobbyId': 'lobbyId'};
  const expressionAttributeValues = { ':lobbyid': message.lobbyId };
  const exclusiveStartKey = {};
  
  let queryResult = GameSparks().DynamoDB().QueryIndex(
    tableName,
    indexName,
    keyConditionExpression,
    expressionAttributeNames,
    expressionAttributeValues,
    exclusiveStartKey);
  
  return GameSparks().Messaging().Response({ 'players': queryResult.Items });
}
catch (ex)
{
  return GameSparks().Messaging().Response({ "players": [], "error": ex.message });
}
收到响应
Id: 56f05f7b-65ed-43b7-a8e4-8390dc9faf0e
 Type: Custom.Game.GetPlayersInLobby
 Category: Response
 ResponseTo: 92f4562c-cf9e-4f7a-ac13-444e31b1c93b
 
 {"players":[],"error":"javaException.getCustomerFacingExceptionDetails is not a function"}
Request sent
Id: 92f4562c-cf9e-4f7a-ac13-444e31b1c93b
 Type: Custom.Game.GetPlayersInLobby
 Category: Request
 
 {"lobbyId":"fb3578b6797848448d5facca5555d12c"}
profile picture
专家
已提问 5 个月前1 查看次数
1 回答
0

【以下的回答经过翻译处理】 属性值是映射类型。

尝试
{
  const tableName = 'BattleRoyalePlayerLobbyTable';
  const indexName = 'lobbyId-index';
  const keyConditionExpression = '# lobbyId = : lobbyid';
  const expressionAttributeNames = {'#lobyId':'lobbyId'};
  const expressionAttributeValues = { ': lobbyid':message.lobbyId};
  const exclusiveStartKey = {};

  let queryResult = GameSparks()。DynamoDB()。QueryIndex(
    tableName,
    indexName,
    keyConditionExpression,
    expressionAttributeNames,
    expressionAttributeValues,
    exclusiveStartKey);

  return GameSparks().Messaging().Response({ 'players': queryResult.Items });
}
catch(ex)
{
  return GameSparks().Messaging().Response({ "players": [], "error": ex.message });
}

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则