Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 21st, 2024, 5:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Sorting question
PostPosted: February 28th, 2017, 2:59 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
I found an old script to sort scores.
The problem is that it sorts the wrong way. (biggest number on top, lowest number last)
I tried several things but my scripting skills not that good to solve the problem.
Who can help me.

Ad


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

_________________
Opus Pro v9.75
Windows 10 on HP EliteBook i7
http://www.csnmedia.nl


For this message Ad Mulders has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Sorting question
PostPosted: March 2nd, 2017, 12:09 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
You don't need it - as there is already a sort method:

Code:
myNumbers = new Array(3,7,2,9,5,9,0)

//lowest to highest
myNumbers.sort(function(a, b){return a-b})

Debug.trace(myNumbers+'\n')


//highest to lowest
myNumbers.sort(function(a, b){return b-a})
Debug.trace(myNumbers)


The function passed as a parameter (inside the brackets) can be customised for more complex solutions but these two sort integers.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


For this message mackavi has been thanked by : Ad Mulders


Top
 Profile Visit website  
 
 Post subject: Re: Sorting question
PostPosted: March 2nd, 2017, 7:33 am 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
Thanks for your reaction.
What do i have to change on my script to get work? :roll:

[code]obs= new Array(t1,t2,t3,t4)//build an array to hold the text objects
//to add more, just create more text boxes, follow the pattern,
//and add them to the array

d= new Array()//this array will hold the text boxes in sorted order
//according to the scores


function sortit()
{
b= new Array()//create an array to hold the sorted scores

c= new Array(sc1,sc2,sc3,sc4)//this array holds the scores unsorted
del =0

//=================================
//for some reason, Opus treats the array of scores as strings
//so we'll change them to numbers
for(i=0;i<c.length;i++)
{
c[i]=String.number(c[i])
}
//=================================

for(i=0;i<c.length;i++)//these nested loops sort the scores and
//their coresponding text objects
{
max=0
for(j=0;j<c.length;j++)
{
if(c[j]<=max)
{
continue
}
else
{
max=c[j]
b[i]=max
del=j
}
tob=obs[j]
d[i]=tob

}
c[del]=0
}
//End nested loops

j=105//Y position of the top text box

for(i=0;i<d.length;i++)//this loop sets the position of the text boxes
//in their sorted order starting at Y position 105
{
d[i].SetPositionY(j,.3,true)
j=j+40//distance between the text box centers
}
}
[/code]

_________________
Opus Pro v9.75
Windows 10 on HP EliteBook i7
http://www.csnmedia.nl


For this message Ad Mulders has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Sorting question
PostPosted: March 2nd, 2017, 4:50 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Okay, the function is just for sorting numbers - you need to rearrange the boxes - so I'd just reverse the reshuffle:


Code:
obs= new Array(t1,t2,t3,t4)//build an array to hold the text objects
//to add more, just create more text boxes, follow the pattern,
//and add them to the array

d= new Array()//this array will hold the text boxes in sorted order
//according to the scores


function sortit()
{
b= new Array()//create an array to hold the sorted scores

c= new Array(sc1,sc2,sc3,sc4)//this array holds the scores unsorted
del =0

//=================================
//for some reason, Opus treats the array of scores as strings
//so we'll change them to numbers
for(i=0;i<c.length;i++)

{

c[i]=String.number(c[i])
}
//=================================

for(i=0;i<c.length;i++)//these nested loops sort the scores and
//their coresponding text objects
{
max=0
for(j=0;j<c.length;j++)
{
if(c[j]<=max)
{
continue
}
else
{
max=c[j]
b[i]=max
del=j
}
tob=obs[j]
d[i]=tob

}
c[del]=0
}
//End nested loops

j=105//Y position of the top text box

for(i=d.length-1;i>=0;i--)//this loop sets the position of the text boxes

//in their sorted order starting at Y position 105
{
d[i].SetPositionY(j,.3,true)
j=j+40//distance between the text box centers
}
}


</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Sorting question
PostPosted: March 2nd, 2017, 7:19 pm 
Offline

Joined: May 16th, 2008, 4:50 pm
Posts: 368
Location: Berghem The Netherlands
Opus: Opus Pro 9.75
OS: Windows 10
System: `HP
Thanks

_________________
Opus Pro v9.75
Windows 10 on HP EliteBook i7
http://www.csnmedia.nl


For this message Ad Mulders has been thanked by : mackavi


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

All times are UTC [ DST ]


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group