How to print dictionary

When i try to print a dictionary it just prints the keys as 1,2,3 etc.

What exactly are you wanting to print out though?

1 Like

with new new output you can expand the keys and see their values

1 Like
local function playerAdded(player)
	local success, data = pcall(function ()
		return CardStore:GetAsync(player.UserId)
	end)
	if success then
		if data then
			CardCache[player.UserId] = data
			MatchService.TemporaryCache[player.UserId] = {CardCache[player.UserId]}
		else
			CardCache[player.UserId] = createDefaultDeck()
			MatchService.TemporaryCache[player.UserId] = {CardCache[player.UserId]}
		end
	else
		-- Handle case of error; kick, block saving, etc.
		warn(string.format("Could not load data for %s: %s", player.Name, data))
	end

	

	for _, card in pairs(CardCache[player.UserId]) do
--nothing here yet
print(player)
	end
	print(MatchService.TemporaryCache[player.UserId])
	CardService.CardCache = CardCache

end

Im trying to print a cache and the userid key isn’t visible.

image
Only the last dictionary shows keys.
Also the one in the middle is an array.

This works? The second thing pcall returns is error.


This is how to do it

local data
local success,err = pcall(function()
     data = CardStore:GetAsync(player.UserId
end)

if not success then
   warn(err)
   player:Kick()
end

if data then
   -- 
else
   -- new player
end

Hey you’re right, it does work though.

I think it’s because of what is returned.

if you want to see the keys in TemporaryCache do

print(MatchService.TemporaryCache)

Cool I didn’t know that

printing temporarycache results in this
image
prints out the player key as -1

you are using a testing server (to play with multiple accounts) the ids for the testing players are always -1, -2, -3 etc

1 Like

Oh ok, did not know. :shallow_pan_of_food:

1 Like