local function CleanGrid()
if currentTask then
task.cancel(currentTask)
currentTask = nil
end
for _, v in ItemFrames do
v:Destroy()
end
ItemFrames = {}
end
local function UpdateGrid(Items)
if currentTask then
warn("cancelling")
task.cancel(currentTask)
end
currentTask = coroutine.create(function()
for _, ItemData in Items do
--local ItemButton = CreateItemFrame.Create(ItemData)
local ItemButton = Instance.new("TextButton")
ItemButton.Text = ItemData.AssetType
ItemButton.Parent = Grid
table.insert(ItemFrames, ItemButton)
task.wait()
end
end)
task.spawn(currentTask)
end
local function LoadNextPage()
if not PagesData or PagesData.IsFinished or IsLoadingNextPage then
return
end
IsLoadingNextPage = true
local success, err = pcall(function()
PagesData:AdvanceToNextPageAsync()
end)
if success then
UpdateGrid(PagesData:GetCurrentPage())
end
IsLoadingNextPage = false
end
function module.LoadSubCategory(SubData)
CleanGrid()
Core.CatalogParams.AssetTypes = SubData.AssetTypes or {}
Core.CatalogParams.BundleTypes = SubData.BundleTypes or {}
Core.CatalogParams.CreatorName = SubData.CreatorName or ""
Core.CatalogParams.CategoryFilter = SubData.CategoryFilter or Enum.CatalogCategoryFilter.None
Core.CatalogParams.SortType = SubData.SortType or Enum.CatalogSortType.Relevance
Core.CatalogParams.IncludeOffSale = SubData.IncludeOffSale;
PagesData = AES:SearchCatalogAsync(Core.CatalogParams)
UpdateGrid(PagesData:GetCurrentPage())
end
the problem i have:
for example
UpdateGrid() (from module.LoadSubCategory)
while it creating frame launches new UpdateGrid() (from module.LoadSubCategory)
and previous frames from updateGrid are cleaning, but some of frames which didn’t have time to be generated continue to be generated even though I used task.cancel
Grid:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
if IsLoadingNextPage then return end
local canvasPosition = Grid.CanvasPosition.Y + Grid.CanvasSize.Y.Offset + 250
local canvasSize = Grid.AbsoluteCanvasSize.Y
if canvasPosition >= canvasSize then
LoadNextPage()
end
end)
local function CleanGrid()
if currentTask then
coroutine.close(currentTask)
currentTask = nil
end
for _, v in ItemFrames do
v:Destroy()
end
ItemFrames = {}
end
local coroutines = {}
local function UpdateGrid(Items)
if currentTask then
coroutine.close(currentTask)
currentTask = nil
end
currentTask = coroutine.create(function()
--[[
for _, ItemData in Items do
--local ItemButton = CreateItemFrame.Create(ItemData)
local ItemButton = Instance.new("TextButton")
ItemButton.Text = ItemData.AssetType
ItemButton.Parent = Grid
table.insert(ItemFrames, ItemButton)
end
]]
local i = 1
while Items[i] do
-- print("generating new frame")
local ItemData = Items[i]
local ItemButton = Instance.new("TextButton")
ItemButton.Text = ItemData.AssetType
ItemButton.Parent = Grid
table.insert(ItemFrames, ItemButton)
i += 1
task.wait()
end
end)
coroutine.resume(currentTask)
end