Calling scoreboards on difrent boardIDs at once only returns the first

It looks like the problem is that the Lua wrapper stores a reference to the callback function in a global, so when you send two requests in a row the second overwrites the first. I think we originally only had one scoreboard per game and then didn't consider this possibility when we added multiple scoreboards. Though I do see a comment about chaining score list calls so maybe Marc intended it to be used that way but forgot to mention it in the docs.

I'll file this, will either add a table so we can track multiple requests or document the behavior and log a warning if you send simultaneous requests. From what Matt says it sounds like chaining works better anyway, so you could use a helper function to make that easier, something like

local requests = {}

function requestScoreboard(name, callback)
	requests[#requests+1] = { name, callback }

	local function getNextRequest()
		pd.scoreboards.getScores(requests[1][1], function(listname, score)
			local callback = requests[1][2]
			-- could also verify that listname == requests[1][1]
			callback(listname, score)
			table.remove(requests, 1)
			
			if #requests > 1 then getNextRequest() end
		end)
	end
	
	if #requests == 1 then getNextRequest() end
end

That's completely untested code (I don't have a game on Catalog, for one) but hopefully it shows the idea even if it doesn't work right. :sweat_smile:

2 Likes