Skip to content

Commit

Permalink
Merge pull request #40 from FireBird702/main
Browse files Browse the repository at this point in the history
Update docs
  • Loading branch information
noahrepublic authored Oct 12, 2024
2 parents 3973cbd + 6caa989 commit e896328
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
24 changes: 20 additions & 4 deletions docs/DevProducts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ sidebar_position: 5

The following example shows how you would handle developer product purchases:

```lua
-- DataTemplate.luau

local dataTemplate = {
PurchaseHistory = {},

Coins = 0,
}

export type template = typeof(dataTemplate)

return table.freeze(dataTemplate)
```

```lua
-- DevProducts.luau

local DataKeep = require(path_to_datakeep)
local DataTemplate = require(path_to_datatemplate)

local devProducts = {
[product_id_here] = function(player: Player, keep: DataKeep.Keep)
[product_id_here] = function(player: Player, keep: DataKeep.Keep<DataTemplate.template, {}>)
keep.Data.Coins += 100

print(`{player.Name} purchased some coins!`)
Expand All @@ -29,11 +44,12 @@ local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local DataKeep = require(path_to_datakeep)
local DataTemplate = require(path_to_datatemplate)
local DevProducts = require(path_to_devproducts)

local purchaseHistoryLimit = 50

local function setProcessReceipt(store: DataKeep.Store, keyPrefix: string)
local function setProcessReceipt(store: DataKeep.Store<DataTemplate.template, {}>, keyPrefix: string)
local function processReceipt(receiptInfo): Enum.ProductPurchaseDecision
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)

Expand Down Expand Up @@ -104,14 +120,14 @@ return setProcessReceipt
local Players = game:GetService("Players")

local DataKeep = require(path_to_datakeep)
local DataTemplate = require(path_to_datatemplate)
local SetProcessReceipt = require(path_to_setprocessreceipt)

local dataTemplate = { Coins = 0 }
local keyPrefix = "Player_"

local loadedKeeps = {}

local keepStore = DataKeep.GetStore("PlayerData", dataTemplate, {}):expect()
local keepStore = DataKeep.GetStore("PlayerData", DataTemplate, {}):expect()

local function onPlayerAdded(player: Player)
keepStore:LoadKeep(keyPrefix .. player.UserId):andThen(function(keep)
Expand Down
5 changes: 2 additions & 3 deletions docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ local Players = game:GetService("Players")
--> Includes

local DataKeep = require(path_to_datakeep)

local DataTemplate = require(script.Parent.DataTemplate)
local DataTemplate = require(path_to_datatemplate)

--> Module Definition

Expand Down Expand Up @@ -199,7 +198,7 @@ end

--> Constructor

function Player.new(player)
function Player.new(player: Player)
local self = setmetatable({
Player = player,

Expand Down

0 comments on commit e896328

Please sign in to comment.