Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Array sorting

Nira
2019-04-15
2019-04-17
  • Nira - 2019-04-15

    I try to make a game that works on time, for now it works but i want to make some adjustments.

    I would like to make the array with the fastest times.
    I created a function in visualization where you have to enter your name, the time played must be linked to the name entered and sorted in the array.

    I have a start and stop sensor for detecting the played time.

    Is there sombody who can help me in the right direction?

    IMG: Codesys1.JPG

     
  • Dave-76 - 2019-04-15

    I would do it like this:
    Create a structure with string (for the players name) and time
    Declare f.eg. TopTen : Array [1..10] of struct xxxxx
    do in a loop:
    if Gespeelde_Tijd is higher than the time in Array10 do nothing and exit loop.
    if Gespeelde_Tijd is lower than the time in Array10 and higher than Array9 replace Array10 with Gespeelde_Tijd and name and exit loop.
    if Gespeelde_Tijd is lower than the time in Array9 then copy Array9 to Array10 and go to next loop.

    in the next loop cycle:
    if Gespeelde_Tijd is lower than the time in Array8 then
    copy Array8 to Array9 and got to next loop cycle
    else store Gespeelde_Tijd and name of the player in Array9 and exit loop

    and so on.
    Hope you can understand my english explanations, my native language is german
    and i'm rigth, you are dutch?

     
  • Nira - 2019-04-17

    Hello, and thank you for your replay.

    I'm from Holland indeed.
    I appreciate your help.

    Can you axplain create a structure with string (for the players name) and time?
    Do i have to that in a DUT?

    Declare f.eg. TopTen : Array [1..10] of struct xxxxx
    I do this in the PLC_PRG?

    Do i also have to make the loop in the PLC_PRG?
    I program in funtion blocks how do i add the text?
    if Gespeelde_Tijd is higher than the time in Array10 do nothing and exit loop.
    if Gespeelde_Tijd is lower than the time in Array10 and higher than Array9 replace Array10 with Gespeelde_Tijd and name and exit loop.
    if Gespeelde_Tijd is lower than the time in Array9 then copy Array9 to Array10 and go to next loop.
    Or can i make a POU in structure text?

    Sorry for the beginners questions

     

Log in to post a comment.