Windows
Simulator 2.40
*This is also true for addScore
TLDR; you can't easily call getScores(A) and getScores(B) without putting them together.
It seems unnecessarily hard but if I am being dumb or there is a good reason please tell me.
Update the scoreboards API doc with more info?
Full explanation:
I am trying to receive the data for two scoreboards: lemansone and spaone
pd.scoreboards.getScores("lemansone", function(code, trackTimeTemp)
lemansoneScoreboardsRank[1] = trackTimeTemp.scores[1].rank
lemansoneScoreboardsPlayer[1] = trackTimeTemp.scores[1].player
lemansoneScoreboardsValue[1] = trackTimeTemp.scores[1].value
print("lemansone")
printTable(trackTimeTemp)
printTable(code)
end)
pd.scoreboards.getScores("spaone", function(code, trackTimeTemp2)
spaoneScoreboardsRank[1] = trackTimeTemp2.scores[1].rank
spaoneScoreboardsPlayer[1] = trackTimeTemp2.scores[1].player
spaoneScoreboardsValue[1] = trackTimeTemp2.scores[1].value
print("spaone")
printTable(trackTimeTemp2)
printTable(code)
end)
Only this prints:
lemansone
{
[lastUpdated] = 762985634,
[scores] = {
{
[player] = PastaMan,
[rank] = 1,
[value] = 24,
},
},
}
{
[code] = OK,
}
If I write it as:
pd.scoreboards.getScores("lemansone", function(code, trackTimeTemp)
lemansoneScoreboardsRank[1] = trackTimeTemp.scores[1].rank
lemansoneScoreboardsPlayer[1] = trackTimeTemp.scores[1].player
lemansoneScoreboardsValue[1] = trackTimeTemp.scores[1].value
print("lemansone")
printTable(trackTimeTemp)
printTable(code)
pd.scoreboards.getScores("spaone", function(code, trackTimeTemp2)
spaoneScoreboardsRank[1] = trackTimeTemp2.scores[1].rank
spaoneScoreboardsPlayer[1] = trackTimeTemp2.scores[1].player
spaoneScoreboardsValue[1] = trackTimeTemp2.scores[1].value
print("spaone")
printTable(trackTimeTemp2)
printTable(code)
end)
end)
And get:
lemansone
{
[lastUpdated] = 762985699,
[scores] = {
{
[player] = PastaMan,
[rank] = 1,
[value] = 24,
},
},
}
{
[code] = OK,
}
spaone
{
[lastUpdated] = 762985700,
[scores] = {
{
[player] = PastaMan,
[rank] = 1,
[value] = 90,
},
},
}
{
[code] = OK,
}
This makes it impossible to use a for loop.
For instance:
local trackNames = {"lemansone", "spaone", "monzathree", "ovalthree", "albertthree"}
local scoreboards = {
lemansone = {rank = {}, player = {}, value = {}},
spaone = {rank = {}, player = {}, value = {}},
monzathree = {rank = {}, player = {}, value = {}},
ovalthree = {rank = {}, player = {}, value = {}},
albertthree = {rank = {}, player = {}, value = {}}
}
for i, trackName in ipairs(trackNames) do
pd.scoreboards.getScores(trackName, function(code, trackTimeTemp)
if trackTimeTemp and trackTimeTemp.scores and trackTimeTemp.scores[1] then
scoreboards[trackName].rank[1] = trackTimeTemp.scores[1].rank
scoreboards[trackName].player[1] = trackTimeTemp.scores[1].player
scoreboards[trackName].value[1] = trackTimeTemp.scores[1].value
print(trackName)
printTable(trackTimeTemp)
end
end)
end
Only prints:
lemansone
{
[lastUpdated] = 762985823,
[scores] = {
{
[player] = PastaMan,
[rank] = 1,
[value] = 24,
},
},
}
Solution: This is the only way to call them all easily. (Works best on sim and poorly on device. Simply writing it out is better on device.)
local trackNames = {"lemansone", "spaone", "monzathree", "ovalthree", "albertthree"}
local scoreboards = {
lemansone = {rank = {}, player = {}, value = {}},
spaone = {rank = {}, player = {}, value = {}},
monzathree = {rank = {}, player = {}, value = {}},
ovalthree = {rank = {}, player = {}, value = {}},
albertthree = {rank = {}, player = {}, value = {}}
}
local function getScoresSequentially(index)
if index <= #trackNames then
local trackName = trackNames[index]
pd.scoreboards.getScores(trackName, function(code, trackTimeTemp)
if trackTimeTemp and trackTimeTemp.scores and trackTimeTemp.scores[1] then
scoreboards[trackName].rank[1] = trackTimeTemp.scores[1].rank
scoreboards[trackName].player[1] = trackTimeTemp.scores[1].player
scoreboards[trackName].value[1] = trackTimeTemp.scores[1].value
print(trackName)
printTable(trackTimeTemp)
end
-- Call getScoresSequentially for the next track
getScoresSequentially(index + 1)
end)
end
end
-- Start the sequence
getScoresSequentially(1)