Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently September 28th, 2024, 3:15 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Selecting and showing a random sub group
PostPosted: June 7th, 2005, 2:10 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
The following code on page-show sets up the number of objects:

RandomList(10)
for (n=1 to RandomList)
{
eval("obj_" + randomlist[selected-1] + ".Show()")
}

and this script, spaces those objects, at random, evenly down the screen:

function RandomList(number) {
numberlist = new Array();
for (count = 1; count <= number; count++) {
numberlist[count] = count;
}
randomlist = new Array();
for (count = numberlist.length - 1; count > 0; count--) {
picked = Math.floor(Math.random()*count)+1;
randomlist[count-1] = numberlist[picked];
eval("obj_" + count + ".SetPositionY(" + ((numberlist[picked]*30)+170) + ")")
numberlist[picked] = numberlist[count];
}
}

I have been trying to edit it so that it functions in the same way, but selects the ten objects from a batch of 15 objects (obj_1 through obj_15)

and I’m tying myself in knots and getting nowhere fast.

Have tried putting in an if statement and counts to surround the above code, and also inserted it within the code at different places. Have managed to get it to show just ten objects, but they are always the objects numbered 1 to 10! I'm trying to find the programming equivalent, for me, of finding a needle in a haystack.

I would really appreciate some help on this.

Many thanks,

John


Last edited by JMahoney on June 12th, 2005, 1:50 pm, edited 1 time in total.

Top
 Profile Visit website  
 
 Post subject:
PostPosted: June 10th, 2005, 4:41 pm 
Offline

Joined: November 28th, 2004, 6:05 am
Posts: 141
Location: USA
Hi John

same problem as last time :-)

eval("obj_" + count + ".SetPositionY(" + ((numberlist[picked]*30)+170) + ")")


eval("obj_" + count +

will always give you obj_10 , obj_9 , obj_8 ...

try eval("obj_" + randomlist[count] +....

HTH
Chris

_________________
Opus Resources and Services


Top
 Profile Visit website  
 
 Post subject:
PostPosted: June 10th, 2005, 5:04 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Hi Chris,

Many thanks for your response - you've lost me. I understand your ref to 'same prob as last time' :oops: - except.

The code as quoted works perfectly - pumps up the number of designated objects in random order down the screen.

What I cannot get it to do is display a random subset. So, currently it will give me for example: 2, 5, 3, 7, 9, 10, 1 etc up to the whole 15 objects. I now want to be able to display say only 10 of the objects randomly selected from all 15.

Edited: I attach an imp file that shows the 15 objects randomising each time I refresh the page. I cannot work out how to show just a random subset of, say, any ten of the fifteen. I'm repeating myself!!

John


Top
 Profile Visit website  
 
 Post subject:
PostPosted: June 10th, 2005, 5:51 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Attachment here - I hope

Well - I would add an attachment but the 31K file causes the following message 'Sorry, but the maximum filesize for all Attachments is reached. Please contact the Board Administrator if you have questions.'

Stymied! :evil:

John

Still cannot add attachments 11.30am 13th June


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 3 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