cloud_synchronise 云端同步


这个函数通常在新的游戏的开始被调用,用于检索云端服务器上存储的游戏的启动。The function returns a unique id value which would then be used in the Asynchronous Cloud Event to retrieve the relevant information from the ds_map that is created.

这个函数用于向云端发送数据, 并触发相应的异步事件。In this event, you can check the returned async_load ds_map for the following values:

  • "status": This holds the status code, where a negative value denotes an error, a description of which will be contained in the "errorString". A value of 0 (or a positive value) indicates a success(see below for exact values), and the "resultString" will contain the returned data or a success message.

  • "id": The id which was returned from the called function. If you fire off a series of cloud_ requests then you need to know which one you are getting the reply to, and so you would use this value to compare to the value you stored when you originally sent the request to find the right one.

  • "description": The description of the last uploaded file.

  • "resultString": This holds a string which is the data blob returned from the cloud.

  • "errorString": returns an Error String for any error.

返回值 "status" 的详细映射关系如下如下:

状态值 errorString / resultString 描述
-1 errorString = "Not logged in to <SERVICE>" 未能成功登陆到给定的云服务。
0 resultString = recovered data 从云端下载新的游戏数据(在 cloud_synchronise 后调用)。
1 resultString = "AlreadySynchronized" 自从上次调用以来 cloud_synchronise 没有新的数据。
2 resultString = "ConflictDeferral" 遇到冲突,但玩家选择忽略它。
3 resultString = "GameUploadSuccess" 来自 cloud_string_savecloud_file_save的数据被成功的上传到云端。
-n errorString = Description of error 负数意味着同步失败。





Extended 举例:

这个函数会在 开始事件(Game Start Event) 或者当一个 object 被放置在你的游戏的第一个房间中时被调用,通过这种思路来从云端服务器检查是否有数据更新。

cloud_check = cloud_synchronise();

你需要检查从异步 Cloud Event 返回的 ds_map来获得返回的 status 和具体字符串。 你可以通过如下代码来获得::

if ds_map_find_value(async_load, "id") == cloud_check
   if ds_map_find_value(async_load, "status") < 0
      show_message_async("Cloud Services not available. Please check connectivity.");
      if ds_map_find_value(async_load, "status") == 0
         var file = file_text_open_write("Save.txt");
         file_text_write_string(file, ds_map_find_value(async_load, "resultString"));

上面的代码通过检查以确保异步调用的函数正确性,然后返回云端 ds_map 的 status。如果 status 是一个负数, 则告知用户这里出现了错误, 否则,代码将继续获取同步的数据并将它写入一个文本文件供以后使用。