Dictionary For Each Key order question

Discussion and feedback on Construct 2

Post » Tue May 27, 2014 3:45 pm

What exactly determines the order when using For Each Key with a dictionary object? It's not chronological or key based as far as I can tell.

Currently using a dictionary to store the chat text coming from the server in my MMO with the server's chat message ID as the key to prevent accidentally duplicating lines in the chat display.

I had thought that it was either chronological or based off the key since the chat dictionary starts with a "system" message with index 0, and all the messages that the server sends come through with non-zero indexes. When I populate my text object with the information returned from the For Each Key event, they are in the exact order the server sent them, with the system message at the top. So far, so good.

For record keeping and to cut down on information passed from the server to the client the client stores the last message ID it received, and uses that to prompt the server to check for any messages that have a higher ID so that only fresh messages are sent on a chat update.

I have recently added a system alert type message when the server recognizes I've uploaded a new version of the client. When the condition is right, it increments the LastChatID by .01 (giving a potential 100 messages without risk of duplicating the next ChatID's key), then inserts a new chat message using the same method I use to insert the first system message and the new incoming chat messages.

At first glance, it works exactly as planned...the system message shows up at the bottom of the scrolling chat when it's received. However, the next time it grabs fresh chat messages, instead of the System message being between what was the previous last chat message and the new chat messages, it is instead pushed to the bottom of the text object. This means that even though it chronologically was not the last added to the dictionary nor is it's key the highest number (or string...tried both ways. And the string "100.001" evaluates to more than "100" and less than "101" in javascript and C2...I even verified this.) that system message still is the last key returned during the for each key loop.

I'm stumped as to exactly how the order is determined. It's not a major issue at the moment, since the system message can only be generated once when I upload a new client, but I have plans for more system messages to be injected as things need to be brought to the player's attention. Fairly soon, they will have a full screen of nothing but system messages and have to keep scrolling up to see the chat or refresh their browser.

I'm loath to use a full array for this, since it's overkill for the minimal information I store and would take a considerable rewrite of the chat handling routine.
B
27
S
8
G
3
Posts: 210
Reputation: 6,038

Post » Thu May 29, 2014 12:19 pm

Pitty. Was hoping either someone would know or a developer would comment. I am going to rewrite the whole thing anyway, but this is something that I would like to have the working knowledge to fill in gaps.
B
27
S
8
G
3
Posts: 210
Reputation: 6,038


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 24 guests