question

Tyler Boesch avatar image
Tyler Boesch asked

Title news not displaying in proper order

So I'm not sure if I am doing something wrong or not but I can't get ONE of my title news to display in the correct order. I have changed timestamps, deleted and remade each title news, rewrote code, and I'm not sure what else to do.

Here is how my title news looks in the game manager...

Here is my code for retrieving the title news data.

for(int i = 0; i < result.News.Count; i++) {
			gameObject.GetComponent<Text>().text = gameObject.GetComponent<Text>().text.Insert(0, result.News[i].Title + "\n");
		}

This all works properly but when I have it display the titles, it displays in this order...

What am I doing wrong?? This is driving me crazy!

Thank you in advance wonderful people! :)

unity3dTitle News
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

It is because the Title News list returned in the callback result is ordered by Title News ID, and as far as I know, the ID is generated via date but will not completely follow the real date order. I think you need to sort it according to timestamp field for a better gameplay experience.

You are free to send a thread in our Feature Requests Forum and more votes from other users in our community may help with the priority.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tyler Boesch avatar image Tyler Boesch commented ·

From another post made by @Brendan, he said that the order was sorted by the timestamp already so why isn't my order in timestamp order already? The order is getting mixed up somewhere down the line.

1 Like 1 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com Tyler Boesch commented ·

@Tyler Boesch I believe he's saying that, if sorted by timestamp, the sorted list/array would be with the most-recent news element at the top (the 0 index).

In either scenario, here's what we do in our title. We use C# in Unity and Linq:

To get the ordered list (with the first being the most recent):

[GetTitleNewsResult].News.OrderByDescending(x => x.Timestamp)

To get the most recent element in the list (from the Linq ordered pair), you can just get the FirstOrDefault() from the ordered pair like so:

[GetTitleNewsResult].News.OrderByDescending(x => x.Timestamp).FirstOrDefault()

However, you can use any other sorting method if you don't want to use Linq.

0 Likes 0 ·
Tyler Boesch avatar image Tyler Boesch brandon@uprootstudios.com commented ·

Thank you for the suggestion! However, I just tried both of these options and this was the outcome on both...

I think for now I'm just gonna accept that the news items will never be in order and wait until I can hire 200 MIT coders to figure out why this garbage isn't working. I'll revisit this problem down the road after I have had time to settle down.

Thank you for your help though guys! I truely appreciate it!! :)

0 Likes 0 ·
Show more comments
Tyler Boesch avatar image Tyler Boesch commented ·

Alright I was kind of hoping to avoid that but that's ok. At least I have a direction now. Thank you!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.