Bubble sort not working in project (Answered)

  • The code I replicated exactly from a bubble sort tutorial project doesn't want to properly sort in my game. The array in the tutorial project properly sorts from least to greatest. But in my project, it's sorting by the first number just like the default Sort function.

    EDIT: Images of the code: imgur.com/a/A66TgvB

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't understand your problem..

    Are you saying that "28,F" should come before "248,H" in sorted array?

    This is happening because you are sorting string values.

    If you want to sort by numbers, I suggest you make a 2D array, put numbers at Y:0 and letters at Y:1, then just use the Array Sort action.

    Note, that in this case numbers and letters will be stored in different array elements. If you need to combine them, you'll have to do this:

    Array.At(x,0) & "," & Array.At(x,1)

  • I don't understand your problem..

    Are you saying that "28,F" should come before "248,H" in sorted array?

    This is happening because you are sorting string values.

    If you want to sort by numbers, I suggest you make a 2D array, put numbers at Y:0 and letters at Y:1, then just use the Array Sort action.

    Note, that in this case numbers and letters will be stored in different array elements. If you need to combine them, you'll have to do this:

    Array.At(x,0) & "," & Array.At(x,1)

    Yes, I'm saying "28,F" should come before "248,H". The sorting is for a high scores screen and the letters represent the names for now.

    It's strange that it seems the bubble sort tutorial project doesn't have any problems sorting strings. I was hoping to shortcut things by storing the number and name in the same spot, but if this will 100% fix everything, I'll separate them. Thanks.

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