如何将数据列表发布到Gamespark Runtime Collection中? Unity C# [英] How To Post A List Of Data Into Gamespark Runtime Collection ? Unity C#

查看:172
本文介绍了如何将数据列表发布到Gamespark Runtime Collection中? Unity C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了如何实现gameparks云代码的问题. 我要添加一个添加发布按钮,数据将保存到gamesparks运行时集合中. 到目前为止,我所做的只是使每个按钮的保存按钮只有一个数据. 但是我需要列出播放器数据列表,以便一个播放器可以将多播放器数据保存到运行时集合中. 以下是我的云代码游戏公园:

    Spark.setScriptData("player_Data", currentPlayer); // return the player via script-data
var playerDataList = Spark.runtimeCollection("playerNewspaper"); // this will get the collection of player data
  var playerID = Spark.getPlayer().getPlayerId(); // first we get the id of the current player
  var playerUsername =Spark.getPlayer().getUserName();
  var newspaper = Spark.getData().newspaper;

  var currentPlayer = {
  "playerID": playerID,
  "playerUsername": playerUsername,
  "player_newspaper": newspaper

  }; // we construct a new player from the data we are about to input into the player data

  playerDataList.insert({
  "playerID": playerID
  }, //Looks for a doc with the id of the current player
  {
  "$set": currentPlayer
  }, // Uses the $set mongo modifier to set old player data to the current player data
  true, // Create the document if it does not exist (upsert)
  false // This query will only affect a single object (multi)
  );

此云代码仅为一个玩家保存一个数据.当我使用相同的ID播放器保存数据时,此方法不起作用.

下面是noSql数据预览: 下面是我的noSql预览数据:

{
 "_id": {
  "$oid": "5850dfdb135f38fb1edbf28c"
 },
 "playerID": "57bffe76b6a70d6e2a3855b7",
 "playerUsername": "dennis",
 "player_newspaper": "{\"ID\":\"57bffg77b6a70d6e2a3855b7\",\"Username\":\"Dennis\",\"itemName\":\"Egg\",\"Comment\":\"Promo Telur 1 Butir cuman murah\",\"Date\":\"12/14/2016\"}"
}

我想列出播放器发布的数据.尽管发帖的人是不同的人.

此列表将发布数据,然后我将使用它查询5个随机数据并将其显示为1,我称之为报纸.

该怎么做?

谢谢 丹尼斯

解决方案

最后,我自己得到了解决方案.

我只是意识到这是mongodb dan javascript.

因此在mongodb中,如果要在此处插入mysql之类的数据:

用于添加数据:

var playerDataList = Spark.runtimeCollection("playerNewspaper"); // this will get the collection of player data
    var playerID = Spark.getPlayer().getPlayerId(); // first we get the id of the current player
    var playerUsername =Spark.getPlayer().getUserName();
    var newspaper = Spark.getData().newspaper;

    var currentPlayer = {
        "playerID": playerID,
        "playerUsername": playerUsername,
        "player_newspaper": newspaper

    }; // we construct a new player from the data we are about to input into the player data

    playerDataList.insert(
    {
      "newspaper" : currentPlayer
    } // Uses the $set mongo modifier to set old player data to the current player data
    );

用于随机加载5项数据:

var playerData = Spark.runtimeCollection("playerNewspaper"); // get the collection data
var currentPlayer = playerData.find().limit(5).skip(Math.random() * playerData.count());

Spark.setScriptData("player_Newspaper", currentPlayer); // return the player via script-data

仅此而已

I got a problem how to implement gamesparks cloud code. I want to make a add posting button, the data will save to gamesparks runtime collection. So far what i have done just make a save button one data for only one for each player. But i need to make a list of player data, so one player can save multiplayer data to runtime collection. Below is my cloud code gamesparks :

    Spark.setScriptData("player_Data", currentPlayer); // return the player via script-data
var playerDataList = Spark.runtimeCollection("playerNewspaper"); // this will get the collection of player data
  var playerID = Spark.getPlayer().getPlayerId(); // first we get the id of the current player
  var playerUsername =Spark.getPlayer().getUserName();
  var newspaper = Spark.getData().newspaper;

  var currentPlayer = {
  "playerID": playerID,
  "playerUsername": playerUsername,
  "player_newspaper": newspaper

  }; // we construct a new player from the data we are about to input into the player data

  playerDataList.insert({
  "playerID": playerID
  }, //Looks for a doc with the id of the current player
  {
  "$set": currentPlayer
  }, // Uses the $set mongo modifier to set old player data to the current player data
  true, // Create the document if it does not exist (upsert)
  false // This query will only affect a single object (multi)
  );

This cloud code only save one data for one player. When i save the data with same ID player it is not worked.

Below is noSql data preview : and below is my noSql preview data :

{
 "_id": {
  "$oid": "5850dfdb135f38fb1edbf28c"
 },
 "playerID": "57bffe76b6a70d6e2a3855b7",
 "playerUsername": "dennis",
 "player_newspaper": "{\"ID\":\"57bffg77b6a70d6e2a3855b7\",\"Username\":\"Dennis\",\"itemName\":\"Egg\",\"Comment\":\"Promo Telur 1 Butir cuman murah\",\"Date\":\"12/14/2016\"}"
}

I want to make a list of data posting by player. Although the posting is a same player of not.

This list posting data then i will use to query random 5 data and show it to unity i call it newspaper.

How to do it ?

Thanks Dennis

解决方案

Finally i got the solution myself.

I just realize this is a mongodb dan javascript.

So in mongodb if you want to insert a data like mysql here to do :

For Add Data :

var playerDataList = Spark.runtimeCollection("playerNewspaper"); // this will get the collection of player data
    var playerID = Spark.getPlayer().getPlayerId(); // first we get the id of the current player
    var playerUsername =Spark.getPlayer().getUserName();
    var newspaper = Spark.getData().newspaper;

    var currentPlayer = {
        "playerID": playerID,
        "playerUsername": playerUsername,
        "player_newspaper": newspaper

    }; // we construct a new player from the data we are about to input into the player data

    playerDataList.insert(
    {
      "newspaper" : currentPlayer
    } // Uses the $set mongo modifier to set old player data to the current player data
    );

For Load Data With random 5 Item :

var playerData = Spark.runtimeCollection("playerNewspaper"); // get the collection data
var currentPlayer = playerData.find().limit(5).skip(Math.random() * playerData.count());

Spark.setScriptData("player_Newspaper", currentPlayer); // return the player via script-data

That's All

这篇关于如何将数据列表发布到Gamespark Runtime Collection中? Unity C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆