Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "@boatbomber/sheetvalues",
"version": "3.0.2",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/boatbomber/SheetValues.git"
},
"contributors": [
"boatbomber"
],
"bugs": {
"url": "https://github.com/boatbomber/SheetValues/issues"
}
"name": "@boatbomber/sheetvalues",
"version": "3.0.3",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/boatbomber/SheetValues.git"
},
"contributors": [
"boatbomber",
"daireb"
],
"bugs": {
"url": "https://github.com/boatbomber/SheetValues/issues"
}
}
28 changes: 23 additions & 5 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ local function DictEquals(a, b)
return true
end

local DummyDatastore = { -- Dummy Datastore object to fall back to if DataStoreService fails
GetAsync = function()
return nil
end,
SetAsync = function() end,
UpdateAsync = function(_, callback)
return callback(nil)
end,
}

local SheetValues = {}

function SheetValues.new(SpreadId: string, SheetId: string?)
Expand All @@ -270,6 +280,15 @@ function SheetValues.new(SpreadId: string, SheetId: string?)

local ChangedEvent = Instance.new("BindableEvent")

local dsSuccess, dsReturn = pcall(DatastoreService.GetDataStore, DatastoreService, GUID, "SheetValues")
local DataStore
if dsSuccess then
DataStore = dsReturn
else
DataStore = DummyDatastore
warn("SheetValues: Failed to get DataStore:", dsReturn)
end

local SheetManager = {
Changed = ChangedEvent.Event,

Expand All @@ -278,7 +297,7 @@ function SheetValues.new(SpreadId: string, SheetId: string?)
Values = {},

_ValueChangeEvents = {},
_DataStore = DatastoreService:GetDataStore(GUID, "SheetValues"),
_DataStore = DataStore,
_MessageListener = nil,
_Alive = true,
}
Expand Down Expand Up @@ -385,13 +404,12 @@ function SheetValues.new(SpreadId: string, SheetId: string?)

-- Send these values to all other servers
if self.LastSource == "Google API" then
local msgSuccess, msgResponse = pcall(
task.spawn(pcall,
MessagingService.PublishAsync,
MessagingService,
GUID,
#json < 1000 and json or "TriggerStore"
)
--if not msgSuccess then warn(msgResponse) end
)
end

return true, "Values updated"
Expand Down Expand Up @@ -469,7 +487,7 @@ function SheetValues.new(SpreadId: string, SheetId: string?)
table.clear(self)
end

pcall(function()
task.spawn(pcall, function()
SheetManager._MessageListener = MessagingService:SubscribeAsync(GUID, function(Msg)
local msgTimestamp = math.floor(Msg.Sent)
if msgTimestamp <= SheetManager.LastUpdated then
Expand Down