Gaming World Forums

General Category => Technology and Programming => Topic started by: Madolah on March 01, 2012, 09:33:15 am

Title: I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction)
Post by: Madolah on March 01, 2012, 09:33:15 am
I'm making a small thing on www.indymix.net (http://www.indymix.net) that retrieves 4 images from a bank folder of images. My problem is that there are duplicate returns coming up as I am retrieving 4 times with no duplicate post restriction.


here is my code for the thing.


<script type="text/javascript">
var gallery =new Array();
gallery[0] = new Array(new Array ("1.png", "#01"), new Array ("2.png", "#02"), new Array ("3.png", "#03"), new Array ("4.png", "#04"), new Array ("5.png", "#05"), new
Array ("6.png", "#06"), new Array ("7.png", "#07"), new Array ("8.png", "#08"), new Array ("9.png", "#09"), new Array ("10.png", "#10"), new Array ("11.png", "#11"));


function pickImageFrom(whichGallery)
{
var idx = Math.floor(Math.random() * gallery[whichGallery].length);


document.write('<a href="' + gallery[whichGallery][idx][1] + '"><img src="images/SCS/' + gallery[whichGallery][idx][0] + '"></a>');
}
</script>




<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />




Now how can I have it (or add something to it) to restrict the 4 retrievals from being duplicates.


Thanks Codemonkeys
Title: I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction)
Post by: Biggles on March 02, 2012, 07:05:52 am
remove the pic from the list after it's been picked, i guess. if i did it, i would have had a function that generates a series of such images picked from a common gallery rather than generating each picture in the document.  then again, i probably would have also done it server-side and done a number of other things differently too.
Title: I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction)
Post by: Madolah on March 02, 2012, 08:20:02 am
I'm open to suggestions and options. as long as  i get task at hand completed.
Title: I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction)
Post by: Madolah on March 03, 2012, 12:01:49 am
<script type="text/javascript">
var gallery = new Array();
gallery[0] = new Array(new Array ("1.png", "#01"), new Array ("2.png", "#02"), new Array ("3.png", "#03"), new Array ("4.png", "#04"), new Array ("5.png", "#05"), new
Array ("6.png", "#06"), new Array ("7.png", "#07"), new Array ("8.png", "#08"), new Array ("9.png", "#09"), new Array ("10.png", "#10"), new Array ("11.png", "#11"));


function pickImageFrom(whichGallery)
{
var idx = Math.floor(Math.random() * gallery[whichGallery].length);

document.write('<a href="' + gallery[whichGallery][idx][1] + '"><img src="images/SCS/' + gallery[whichGallery][idx][0] + '"></a>');
}
</script>


<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />
<script language="javascript">pickImageFrom(0);</script><br />

heres what i got, it only loads 4 images, to anchors not links and has no collision detection to stop duplicate retreivals, which would be nice.
Title: I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction)
Post by: Biggles on March 03, 2012, 05:59:38 am
the only thing changed between the op version and that version is the spacing is different. so do what I said to do. each time a pic is placed on the page, remove it from the list of options. or if you want a different solution, write a function that picks x random images from a list by shuffling it and then iterating through. neither of these are fast solutions for the general case, but they're easy to implement and will not cause performance problems on small lists.
Title: I NEED HELP WITH SCRIPT! (need duplicate retrieval restriction)
Post by: Madolah on March 06, 2012, 02:00:21 am
Got it working after, I couldnt solve the Repeat/Duplicate retrievals from happening, but i got links to work!