排名存储 Rank Data Storage

  • Class:RankDataStore

不在编辑器管理器中显示 Will not show in editor

脚本可访问 Can access in script
此对象脚本可访问,但只有服务器脚本可访问 This object can be accessed from script, but only at server script

简介 Introduction

DataStore不能对存储对象进行排序,所以排名存储满足了开发者对某类数据进行从大到小或从小到大排序,并返回多条数据的需求。它可以调用所有DataStore名下的函数。它与DataStore的不同之处在于它存储的value只能是整数(正负都行)。如果填value参数时为小数,则Set(key,value)Update(key,function)函数无法存入该小数value,并报错提示。
RankDataStore sorts stored objects as well as returns multiple data, which DataStore cannot do so. It also transfers all functions under DataStore. The difference between RankDataStore and DataStore is it can only store whole number values. If parameter value is in decimals, then Set(key,value) and Update(key,function) functions cannot save this decimal and will show as error.

不能用RWObject:New(ClassName)函数创建此对象。
Cannot use RWObject:New(ClassName) function to create this object.

排行存储通过DataStoreService服务接口FindRankDataStore()函数来获得。
Receive sorting storage through DataStoreService service interface FindRankDataStore() function.

排名存储只能在发布后的地图或游戏中正常生效,所以玩家可以将地图发布后在编辑器里进行排名存储的相关测试。在编辑器的测试时排名存储空间与玩家游玩平台上游戏时的排名存储空间不同。
RankDataStore will only work after map and game has been published, so players can run data storage related tests in editor after publishing. While testing in editor, DataStore and gaming data storage are different.

编辑器的数据存储和排名存储中所有已存储的数据都可以通过菜单栏下的测试下的重置玩家信息存储数据按钮来清空,公开的已发布地图存储的玩家数据不会被清除。
DataStore and RankDataStore in Editor can be cleared from resetting player data under menu-testing. Player data in published maps will not be cleared.

函数 Functions

    Set(key,value )
    Set函数会把key和value存进RankDataStore。如果key已有对应的值,Set(key,value)会将新的value强制覆盖原值。
    Set function will save key and value in RankDataStore. If there is already a matching value to the key, then Set(key,value) will overwrite.

    Get(key )
    Get函数可以查询key对应的value,并返回。如果key不存在,则返回nil。
Set(key,value) Get function can look up the values to the keys and then return. If key does not exist, then return nil.

    Remove(key )
    Remove函数可以删除RankDataStore中的对应的key和value,并返回被删除的value。如果key不存在,则返回nil。
Set(key,value) Remove function can delete corresponding value to key in RankDataStore, then return deleted value. If key does not exist, then return nil.

    Update(key,function )
    Update函数可以更新RankDataStore中key对应的value。
    Update function can update the corresponding value to key in RankDataStore.

    Increment(key,delta )
    Increment函数可以使key对应的value增加delta,将新value(value+delta)存储并返回给客户端。
    Increment function can increase the corresponding value by delta, then save and return new value(value+delta).

    GetRank(isAscending,Num,minValue,maxValue)
    GetRank函数可以查询按一定顺序排列的前Num条数据,并返回查询结果。
    GetRank function can look up sorted Num amount of data, then return look up results.

实例 Example

创建一个排行榜,存储和读取金币数,展示金币排行榜的数量最多的前3名。
Create a rank list, save and read amount of gold, show top 3 for most amount of gold

local goldstore = DataStoreService:FindRankDataStore("GoldRank") -- 存储空间命名为"GoldRank" Storage space named as "GoldRank"
local key = "player_000002"

goldstore:Set("X",110) -- 存储一个key为"范蠡",值为110是的数据 Save a key as "X", value as 110
goldstore:Set("player_000001",100)
goldstore:Set("duanmu",95)
goldstore:Set("player_000002",106)
goldstore:Set("player_000003",103)

local value = goldstore:Get(key)
print(key..":"..value)

local goldnumber = goldstore:GetRank(false, 3) -- 获取按降序排序的前3条数据 get the top 3 data from most to least
for k,v in pairs(goldnumber) do
    print("Number" .. k .. ": " .. v.Key .. " " .. tostring(v.IntValue))
end
文档更新时间: 2020-10-07 02:39   作者:刘征