Help here !!! dop2000 or RojoHound or anybody,,, Need to sort numbers from Biggest to small?

0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.

    I already found another method waaayy apart from what you were telling me before I found the perfect code to sort any car rank points in my game

    Please enlighten us about your method of sorting scores in global variables. Even for experienced developers it's never too late to learn!

    Sorting without array >> dropbox.com/scl/fi/gjv75q6wo5j4dctdrc7jj/angka_no-array.capx

    *angka means number

    Sorting without array

    This example uses instance variables, which I was suggesting from the beginning. OP wanted to sort global variables.

    You coded your game badly. We all do it when we first start.

    People here showed you how to do it a better way, they were olite and gave you multiple options, but you were unwilling to learn.

    It's not people helping you giving excuses lol.

    If I did it by myself then tell what it is !!??? Who show me a better way !!???? cause I did it the right in a perfect way and it was totally different from what they told me , and I give my thanks to them < But Im saying that if you a want a work to be done fine then do it yourself and that's what I'm learning here,,,, I created my own code cause none of the example they gave work a 100% not even a 50% ,, its that a problem !!?? I did the code by myself so I don't see any problem with that ,,

    It was a friendly request by the guy that gave the most of his time trying to help. No need to get grumpy.

    I think today is a nice day for a stroll.

    It was a friendly request by the guy that gave the most of his time trying to help. No need to get grumpy.

    I think today is a nice day for a stroll.

    Just watch the video and enjoy !!!

    Maybe some other time.

    Maybe some other time.

    You already did ,,, I know that ,,, cheers

    Sorting without array >> dropbox.com/scl/fi/gjv75q6wo5j4dctdrc7jj/angka_no-array.capx

    *angka means number

    I had like more than four examples as this but none of them works when you are using Global Variables or Instance Variables

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads

    Beta7 So you are saying you found a much better solution. Show it to us please.

    I would like to note that I purely do this for fun. I'm not a professional and have no obligation spend time to help on this forum.

    So to summarize, you have 8 global variables and you'd like to display them sorted high to low, and when you display it you want it to show the variable name with the score.

    To sort you need to get the list of values into some kind of array. That could be comma separated text, an array object or just just use multiple instances of a sprite. In the end they are all arrays just represented in different ways. I guess the main tricky part is sorting the values and knowing what variables the values came from. Anyways here are three different approaches, some of which were already covered, in one way or another, by the other helpful users on this site.

    Method 1. Text based array

    The first is to use a text variable to represent the array. list="01234567". This is the most compact way I could think of. 0 for the first global, 1 for the second and so on. Next to sort we'd have to implement our own sorting algorithm. Simplest and most compact would be bubble sort. Basically it compares two global variables from two adjacent indexes from the list and swaps the indices if needed.

    With this approach the expression chooseindex(index, p1,p2,p3...) is our friend to reduce the amount of events needed to access different globals with less events. Since it's text based the swap operation looks a bit ugly. Well in general all the expressions look busy with this approach.

    The main con with this is having to modify it if you change the number of globals you're sorting.

    dropbox.com/scl/fi/dn5oe5gwq0f9ltblvkazd/sortGlobals.c3p

    --- Three events long with an additional variable.

    Method 2: using the array object

    The second idea is to just populate an array with the global variables and sort that.

    We can recall the variable names by setting the array size to (8,2,1) and setting array.at(i,0) to the value, and (i,1) to the name or index. The sort only looks at values at y=0 and the other y's get swapped along. Anyway, it's easy enough and straightforward to use if you're not trying to avoid the array object at all costs. Most people with previous programming experience like this way.

    One con is the array sort action only sorts low to high. It's not the end of the world though. One fix is to just loop over the array in reverse like in the example, or setting the array with negative values before sorting, and negating them again when displaying.

    dropbox.com/scl/fi/4dz5bwz9ct7ex4anabvo0/sortArray.c3p

    --- Four events long with the array object

    Method 3: Using instances as an array

    With this you create a sprite type, and create enough instances for all the values. Then in events you populate the instance variables from the globals and use for each ordered to display it.

    This is where Construct really shines. It is simpler and looks much cleaner than the other two ideas. You just have to have the instances created beforehand to avoid picking pitfalls.

    dropbox.com/scl/fi/0t4vk3me4xkum6p41lz7l/sortInstanceVariables.c3p

    ---Two events long with an object type and enough instances

    Beta7 So you are saying you found a much better solution. Show it to us please.

    Dint you saw the video I post !!! everybody saw the video but you !? I think tomorrow I'll post it again ,,, so you dont believe me !?? Jajajaja for real !!! ok I'll show you the video on this week ,,, cheeeers

    Not even close to what I did ,,, not even a little and by the way just try to do it as I showed you on the video I posted earlier and then I give cudos to you ,,, cause allllll the capx examples people showed to me are not working the way I did it by myself >> Just try it and you'll see >> and by the way let me tell you something that I do appreciated all the help you do on these forums >> But why now that I dont need what I already learned by myself you are posting capx and try to give some instructions !!?? why at the beginning you told me >> Ohh I dont have time to created capx examples or something like that you said , but know that I already figure out the code by myself you are trying to help !!??? just asking >> Cheers

    I would like to note that I purely do this for fun. I'm not a professional and have no obligation spend time to help on this forum.

    So to summarize, you have 8 global variables and you'd like to display them sorted high to low, and when you display it you want it to show the variable name with the score.

    To sort you need to get the list of values into some kind of array. That could be comma separated text, an array object or just just use multiple instances of a sprite. In the end they are all arrays just represented in different ways. I guess the main tricky part is sorting the values and knowing what variables the values came from. Anyways here are three different approaches, some of which were already covered, in one way or another, by the other helpful users on this site.

    Method 1. Text based array

    The first is to use a text variable to represent the array. list="01234567". This is the most compact way I could think of. 0 for the first global, 1 for the second and so on. Next to sort we'd have to implement our own sorting algorithm. Simplest and most compact would be bubble sort. Basically it compares two global variables from two adjacent indexes from the list and swaps the indices if needed.

    With this approach the expression chooseindex(index, p1,p2,p3...) is our friend to reduce the amount of events needed to access different globals with less events. Since it's text based the swap operation looks a bit ugly. Well in general all the expressions look busy with this approach.

    The main con with this is having to modify it if you change the number of globals you're sorting.

    https://www.dropbox.com/scl/fi/dn5oe5gwq0f9ltblvkazd/sortGlobals.c3p?rlkey=v86rolm7oceh7nhx9myy8ju51&st=pva8a0vh

    --- Three events long with an additional variable.

    Method 2: using the array object

    The second idea is to just populate an array with the global variables and sort that.

    We can recall the variable names by setting the array size to (8,2,1) and setting array.at(i,0) to the value, and (i,1) to the name or index. The sort only looks at values at y=0 and the other y's get swapped along. Anyway, it's easy enough and straightforward to use if you're not trying to avoid the array object at all costs. Most people with previous programming experience like this way.

    One con is the array sort action only sorts low to high. It's not the end of the world though. One fix is to just loop over the array in reverse like in the example, or setting the array with negative values before sorting, and negating them again when displaying.

    https://www.dropbox.com/scl/fi/4dz5bwz9ct7ex4anabvo0/sortArray.c3p?rlkey=z1l9p4xb18mqhfg4k5gkp88t5&st=z6ch8c8d

    --- Four events long with the array object

    Method 3: Using instances as an array

    With this you create a sprite type, and create enough instances for all the values. Then in events you populate the instance variables from the globals and use for each ordered to display it.

    This is where Construct really shines. It is simpler and looks much cleaner than the other two ideas. You just have to have the instances created beforehand to avoid picking pitfalls.

    https://www.dropbox.com/scl/fi/0t4vk3me4xkum6p41lz7l/sortInstanceVariables.c3p?rlkey=95yhgv684hiqtyucvmg7o41cx&st=sh0wfw11

    ---Two events long with an object type and enough instances

    I didn't see the video because you are deleting your comments.

    Oh yes of course ,, I only post videos for a day but not too long,,, cause I'm concentrated on my game project and not on dramas , I think this week I'll post it again for only a moment so you can see exactly the code in progress , do you have an email ,, anyways I think I know your link site

    I didn't see the video because you are deleting your comments.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)