Dictionary won't read the data from another Dictionary ?
Asked Answered
R

9

0

Hi, im using silentwolf for score board for my game, and with scores im also uploading a 'metadata' with it with every player score record.

i can record them, and i can call them in back, but problem start right there,

yield(SilentWolf.Scores.get_high_scores(10,ld_main), "sw_scores_received")
for scores__ in SilentWolf.Scores.scores:
	if scores__ == null:
		print ("<<<<<< scores empty >>>>>>>")
		return
	if scores__ != null:

		var local_dic :Dictionary = scores__["metadata"]
		print ("local_dic check >>>" , local_dic)  # ---> this line include is working, im getting the every metadata 
                                                    # for every recorded score, but after this line, whatever i did try
			                        # a lof of way, but it dosn't work.
						# metadata must be recorded as Dictionary format.
                                                    # i cant get any feedback after this line, its not crashing the game but there is no print. 
		if local_dic.has("icon_1:1"):
			print ("icon 1 loaded")

		if local_dic.has("icon_2:2"):
			print ("icon 2 loaded")

		if local_dic.has("icon_3:3"):
			print ("icon 3 loaded")

		if local_dic.has("icon_4:4"):
			print ("icon 4 loaded")

		if local_dic.has("icon_5:5"):
			print ("icon 5 loaded")

		if local_dic.has("icon_6:6"):
			print ("icon 6 loaded")

		if local_dic.has("icon_7:7"):
			print ("icon 7 loaded")

this is the print ("local_dic check >>>" , local_dic) result:

local_dic check >>>{icon_3:3}
local_dic check >>>{icon_1:1}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_4:4}
local_dic check >>>{icon_6:6}
local_dic check >>>{icon_5:5}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_1:1}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_4:4}
local_dic check >>>{icon_6:6}
local_dic check >>>{icon_5:5}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_1:1}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_4:4}
local_dic check >>>{icon_6:6}
local_dic check >>>{icon_5:5}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_1:1}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_4:4}
local_dic check >>>{icon_6:6}
local_dic check >>>{icon_5:5}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_1:1}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_4:4}
local_dic check >>>{icon_6:6}
local_dic check >>>{icon_5:5}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_1:1}
local_dic check >>>{icon_3:3}
local_dic check >>>{icon_4:4}
local_dic check >>>{icon_6:6}
local_dic check >>>{icon_5:5}

its been 2 days, i still cant figure it out, what is wrong ?

Reformed answered 25/2 at 13:9 Comment(0)
C
0

Reformed Dictionary::has() checks for keys, not for key/value pairs. So:

if local_dict.has("icon_1"):
	print ("icon 1 loaded")
Cob answered 25/2 at 16:59 Comment(0)
R
0

Ohh yes thats work thank you for the anwser, but i have another problem now, and i didn't understand why is happening, now i try to get the metadata every time i call the leaderboard and if metadata is match to specific player record, there will be a icon for player, but dictonery allways return the first record, engish is not my main language so i did a little video for better understandingt,

this is the code that call the metadata:

i think this should work but its not, where do i do wrong ??

Reformed answered 1/3 at 20:56 Comment(0)
C
0

Reformed Print SilentWolf.Scores.scores to see what you actually retrieved. Always print suspicious stuff. It's debugging 101.

Cob answered 1/3 at 22:19 Comment(0)
B
0

Did you try by chance duplicating the dictionary before referencing it (abstraction)?

It could be that your Global is not updating or not populating as you think.

Blunderbuss answered 2/3 at 0:28 Comment(0)
R
0

i still can't figure this out, its looks like so simple but im stuck .s

right now code is like this

yield(SilentWolf.Scores.get_high_scores(10,ld_main), "sw_scores_received")


for scores__ in SilentWolf.Scores.scores:
	if scores__ == null:
		return
	if scores__ != null:
		var local_dic :Dictionary = scores__["metadata"]
		print ("local dic >>>>>" , scores__["metadata"])

		if local_dic.has("0"):
			print ("icon 0 loaded")
			item.get_node("metadata_label").text = "icon_0"

			
		if local_dic.has("1"):
			print ("icon 1 loaded")
			item.get_node("metadata_label").text = "icon_1"


		if local_dic.has("2"):
			print ("icon 2 loaded")
			item.get_node("metadata_label").text = "icon_2"


		if local_dic.has("3"):
			print ("icon 3 loaded")
			item.get_node("metadata_label").text = "icon_3"


		if local_dic.has("4"):
			print ("icon 4 loaded")
			item.get_node("metadata_label").text = "icon_4"


		if local_dic.has("5"):
			print ("icon 5 loaded")
			item.get_node("metadata_label").text = "icon_5"

		if local_dic.has("6"):
			print ("icon 6 loaded")
			item.get_node("metadata_label").text = "icon_6"

and this is print output:
icon 4 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{6:6}
icon 6 loaded
local dic >>>>>{5:5}
icon 5 loaded

local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{6:6}
icon 6 loaded
local dic >>>>>{5:5}
icon 5 loaded

local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{6:6}
icon 6 loaded
local dic >>>>>{5:5}
icon 5 loaded

local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{6:6}
icon 6 loaded
local dic >>>>>{5:5}
icon 5 loaded

local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{6:6}
icon 6 loaded
local dic >>>>>{5:5}
icon 5 loaded

local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{6:6}
icon 6 loaded
local dic >>>>>{5:5}
icon 5 loaded

local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{4:4}
icon 4 loaded
local dic >>>>>{5:5}
icon 5 loaded
local dic >>>>>{6:6}
icon 6 loaded
local dic >>>>>{5:5}
icon 5 loaded

right now there is 7 record on backhand server, and for loop circle all the records cound of record number, there are 7 record and that 7 record call in for loop 7 times, why is that ?

i mean i try the erease elements from the Dictionary when i call the metadata for that record, but when i do that, only first record get listed, rest of the records returns empty, for loop do not check the other if segments,

but when i run its like the script that i did share up there, every records gets a metadata but, only the last recorded data from the backhand server get listed for every record.

its just that, i can't get the logic. whats happening...

Reformed answered 6/3 at 18:56 Comment(0)
C
0

Reformed As I said before, print the whole thing to see what you retrieved. Not piece by piece in a loop but as a whole. Just do:

print(SilentWolf.Scores.scores)
Cob answered 6/3 at 19:40 Comment(0)
R
0

Cob
thanks for the repy,
this is the oputput for this line, this output from _ready function. i also did try the call the value from _ready to in for loop, but thats turn nill.

print(SilentWolf.Scores.scores)

silentwolf >>>>:[{game_id_version:dayboards;1.0.2, ld_name:hour_board, metadata:{3:3}, player_name:evdfeeen, score:29216, score_id:d81c06af-85b7-4cc6-8e3a-0ba52f8371c6, timestamp:1710176458126.531}, {game_id_version:dayboards;1.0.2, ld_name:hour_board, metadata:{4:4}, player_name:feed, score:19671, score_id:c41a251c-2a03-47c4-8518-6e6f6749272c, timestamp:1710176784339.314}, {game_id_version:dayboards;1.0.2, ld_name:hour_board, metadata:{3:3}, player_name:lazim, score:16268, score_id:45300bbb-40f2-4f06-8c04-5f8707d23b01, timestamp:1710177263755.093}, {game_id_version:dayboards;1.0.2, ld_name:hour_board, metadata:{6:6}, player_name:dayaani, score:14720, score_id:473cdf1e-16a8-497d-bc72-e2aee2cfe7d8, timestamp:1710177014575.1521}, {game_id_version:dayboards;1.0.2, ld_name:hour_board, metadata:{4:4}, player_name:aaaaaaaaa, score:11771, score_id:936a4f2a-8bfc-4ba5-9a55-0bdd22be5905, timestamp:1710177456495.644}]

Reformed answered 11/3 at 17:19 Comment(0)
C
0

Reformed Print it immediately before entering the for loop. And for start, make a simple loop that only prints out whole records:

for s in SilentWolf.Scores.scores:
	print(s)

When debugging, always try to reduce your code to the simplest version that shows the bug or unexpected behavior.

Btw. who calls add_item() and when? This function is a coroutine and accidentally calling it again while one instance of it is suspended (via yield) may be causing the problem.

Cob answered 11/3 at 17:41 Comment(0)
R
0

add_item() call by this function

func render_board(scores, local_scores):
	Global.all_scores = scores
	if ld_main in SilentWolf.Scores.ldboard_config and is_default_leaderboard(SilentWolf.Scores.ldboard_config[ld_main]):
		Global.all_scores = merge_scores_with_local_scores(scores, local_scores, max_scores)
		if !scores and !local_scores:
			add_no_scores_message()
	else:
		if !scores:
			add_no_scores_message()
	if !Global.all_scores:
		for score in scores:
			add_item(score.player_name, str(int(score.score)))

	else:
		for score in Global.all_scores:
			add_item(score.player_name, str(int(score.score)))

well, truth be told, i was tryig the add flag for player score records, but, this problem made me lose to much time, im gonna give up on this feature, it seems silentwolf did not built for this kind of feature, cause when i call the metadata from the backhand server , for loop its call them number of times equal the total of record count, there is someting do not add up there. anyway thank you for your time bro 🙂

Reformed answered 16/3 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.