How do I Sort Array?

0 favourites
From the Asset Store
Master Sorting
$69.30 USD
30% off
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • dop2000

    Thank you for the example

    I have now tried yours with a full team sheet,

    And it wipes every value except the positions,

    Please could you take a look at this and see where I'm going wrong:

    dropbox.com/s/3cfhb2h3hswisr7/ArrayProblem.c3p

  • Well, you can't just copy-paste my code into your project and expect it to work.. First, you need to load the JSON data into the array. And in your array player position is at index 2.

  • dop2000

    Thank you so much for your time and help - Sorry for the confusion I have got a working example now with all formations!

  • Since soccer jersey numbers usually go from GK 1, defenders 2,3,4 and so on, wouldn't just sorting that do the trick anyway?

    I mean, since GK is #1 he will always be on top and defenders are usually wearing 2,3,4, so would be next in line

  • Hi dop2000,

    There seems to be an error with your code

    Here is what the array looks like before the player chooses a formation:

    notice how the 2nd value ('richie machin') has a position which is GK

    Heres what the array looks like when they choose 3-4-3

    Now look you can see Richie machin's position has been changed - this shouldn't happen he should be moved to the bottom as he is another GK instead your code swaps a position with him. How can I fix this?

    dropbox.com/s/tpgt7i4qewufm25/V4.c3p

    This is not the only player this is happening to aswell please can you look into this. It seems to me that the only thing that changes in the array is the positioning not the players , how can I get this to move whole lines in the array

  • That's what I told you 2 days ago! Check this comment:

    construct.net/en/forum/construct-3/how-do-i-8/sort-array-152524

    That demo that you gave worked like that. It assigned different roles to the same player depending on the formation.

  • That's what I told you 2 days ago! Check this comment:

    https://www.construct.net/en/forum/construct-3/how-do-i-8/sort-array-152524#forumPost1010451

    That demo that you gave worked like that. It assigned different roles to the same player depending on the formation.

    dop2000

    Sorry for the confusion but how do I get the rows to swap rather than just the position, So if i pick 4-3-3

    rather than the players position changing I want to move the rows so the players positions dont change but their row is moved so 4-3-3 has 4 defenders so 4 players with the DF value will be moved to the front just under the GK rather than just changing the players.

    SO like its a football team and I want to arrange the players into a formation rather than swap their position values

  • This is much more difficult. I suggest copying players to another array. For example, for 3-4-3 formation, loop through the first array, searching players with "DF" role, copy them to another array, repeat this 3 times. Then do the same for "MD" players, repeat 4 times, then 3 times for "AT" players.

    .

    It would be easier without any arrays, if you had sprites for players. Add 18 instances of Player sprite, they can be just invisible rectangles. Define Role instance variable for each player. Then pick the first 3 "DF" players, add them to the team - set "IsInTeam=true" instance variable or something like that. Pick 4 "MD" players, add to the team. Pick 3 "AT" players, add to the team.

  • dop2000

    Thanks for the help,

    could you provide an example on how to search for players and copy them across.

  • Like I said, it's a lot of work. I don't enjoy working with arrays in Construct.

  • Like I said, it's a lot of work. I don't enjoy working with arrays in Construct.

    dop2000

    could you provide, a quick demo or even a photo on how to search for players and get that data

  • Sorry, like I said, it's quite a lot of work. I can do it, but it will not be free. Maybe someone else can help, or there is an easier solution which I overlooked..

  • Sorry, like I said, it's quite a lot of work. I can do it, but it will not be free. Maybe someone else can help, or there is an easier solution which I overlooked..

    dop2000

    I have sent you an email. Do you have discord so we can chat and work something out.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have 3 arrays instead

    One with DF, another with MF and third with attackers,

    Then another array with the final team

    Keepers should always be the first ( 0 ) in the array

    So when you choose for example a 4-3-3 formation fill the next 4 spots in this final team array with values from DF array, next 3 spots with 3 values from MF array and final 3 spots with 3 guys from AT array.

  • Have 3 arrays instead

    One with DF, another with MF and third with attackers,

    Then another array with the final team

    Keepers should always be the first ( 0 ) in the array

    So when you choose for example a 4-3-3 formation fill the next 4 spots in this final team array with values from DF array, next 3 spots with 3 values from MF array and final 3 spots with 3 guys from AT array.

    BadMario

    This is an interesting concept I will try and do it this way.

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