CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Jun 18, 2019 9:47 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Array sorting
PostPosted: Mon Apr 15, 2019 12:57 pm 
Offline

Joined: Fri Feb 01, 2019 5:49 pm
Posts: 6
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?


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: Array sorting
PostPosted: Mon Apr 15, 2019 6:52 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 271
See:

https://www.google.com/amp/s/www.geeksf ... -sort/amp/

Sent from my Moto G (5S) Plus using Tapatalk


Top
   
 Post subject: Re: Array sorting
PostPosted: Mon Apr 15, 2019 10:13 pm 
Offline

Joined: Sun Nov 19, 2017 4:14 pm
Posts: 21
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 :wink:
and i'm rigth, you are dutch?


Top
   
 Post subject: Re: Array sorting
PostPosted: Wed Apr 17, 2019 2:52 pm 
Offline

Joined: Fri Feb 01, 2019 5:49 pm
Posts: 6
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 :oops:


Top
   
 Post subject: Re: Array sorting
PostPosted: Wed Apr 17, 2019 10:07 pm 
Offline

Joined: Sun Nov 19, 2017 4:14 pm
Posts: 21
rtfm: read the f.... manual to learn more about codesys :lol:
https://help.codesys.com/webapp/_cds_tu ... n=3.5.14.0
https://help.codesys.com/webapp/_cds_st ... n=3.5.14.0
https://help.codesys.com/webapp/_cds_da ... n=3.5.14.0

The text isn't ST-code, it should be a idea for you, to find your own way to program this.
Yes, you can create a function like your stopwatch in ST and call it from your PLC_PRG.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited