Ask here your questions to get help using GDevelop.
By Spider_hip
#45993 Hi all.

So let's say I have soccer teams. How can I sort them with points and show in a table or text objects ? Just like league table.
User avatar
By Lizard-13
#45995 Order a list is a bit complex, I made an example :)
Simple order list example
(32.51 KiB) Downloaded 346 times

Press "Space" to switch between an unsorted and a computed-in-place sorted list.

The "magic" is the doble iteration, (variables "i" and "k"), "i" follow a specific item, and "k" check if the others items in the list are greaters or not, finally, sort the list in function of how much items are greaters:
The greatest has 0 items greater, so the greater is in the place List["0"]
The second has 1 item greater, so the greater is in the place List["1"] ...

It will work better if the initial list (unsorted by points), is sorted by (e.g.) name ;)
By Spider_hip
#46013 Hi again,

I really liked your codes. You're very clever indeed :) . I think I just wonder what if there were teams that have same value of greaters.

TO[VariableString(greaters)].Name

If so, the latest team that has same value of greaters will be overwritten to the same TO[ID] I guess ? I don't know if I'm right. If so how can I prevent that ?

Thank you very much :)
User avatar
By Lizard-13
#46018 Ouch! I thought I had prevented it... but I'm testing it now and fails :roll:

Thanks, think of all the possibilities is a geat talent ;)
This (apparently) woks:
(35.98 KiB) Downloaded 197 times

Just added a void array, then I add old greaters values used in it... Finally, If the value is unique just put it in the new list, but if it was used before (it's in the array with old greaters values), increase it until it isn't in the array...
Oh, and made a slight change in the condition "Curent item value >= Other items values", from ">=" to ">", otherway I think it'll not work...

Let me know if something isn't working as expected.
By Spider_hip
#46021 Once again I'm very impressed, thank you really. It works perfect.

I really spent my day to examine your code :) . I felt ashamed to write actually.

Beceause I couldn't get after while part :oops: Greaters_used was a variable but with while function it become structure I guess. and greaters become it's child. So if it become it's child in while loop, shouldn't it always exists ? I mean isn't it like

greaters_used.greaters = greaters

if greaters_used.greaters exists then;

add to greaters

So how doesn't it becomes an infinite loop ?

I'm sorry maybe this is a silly question but I'm not smart enough I guess :oops:
User avatar
By Lizard-13
#46025
I really spent my day to examine your code :) . I felt ashamed to write actually.

Don't worry... about the code: Probably you will not have to write complex codes like this, I mean, you haven't to sort a list everyday in GD, and I can see now it is not easy :P
Also, I have to admit that my codes are usually too complex :oops:

Greaters_used was a variable but with while function it become structure I guess

Exactly :) When you start sorting, you need the array "greaters_used" empty, so you need to delete every child (you can do it if you want), but GD allows you to convert the type of a variable, so I convert it for an instant in a number... and delete every child in one line! :D

So how doesn't it becomes an infinite loop ?

The wile loop checks if the child with the name of "greaters" exists (i.e. "0","1","2"...), if it exists (there is another item in that place), add 1 to "greaters", then the while checks again if the child exist... but this child is greater, some day the "greater" will become a number that isn't in the "greaters_used".
For example, in the file I uploaded here, First_Team has 18 points, and Second_Team = Third_Team = 15 points...
The Second_Team has 1 team "greaters" (remember I change the condition ">=" to ">"), it has no problem with the "greaters_used", so it will be in the index 1 (second position) and the number "1" is added to "greaters_used".
The Third_Team has 1 team "greaters" too, but the while loop check that "1" exists in "greaters_used", so add 1 to "greaters", now the while loop check if "2" exists, it doesn't, so Third_Team is added at index "2", and "2" is added to "greaters_used" :)


Again, I emphatize that maybe there is some straightforward way to order a list, and I'm making it difficult :twisted: