stupid logic is not understanding me...

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

stupid logic is not understanding me...

Post by daring_du on Mon Aug 03, 2009 12:32 pm
([msg=27819]see stupid logic is not understanding me...[/msg])

Hi all,

I'm taking a javascript class and my teacher gave me this script for fading images. However, he doesn't seem to know much about it himself so I'm left wondering about a few things. I hope someone won't mind have a look at my comments within the script to see where my issues (i mean, the stupid logic's issues) are. One set of comments at the beginning and the other more important set at the end. Thanks.

Oh yeah, any helpful links to a dictionary or some kind of glossary which will explain things like "filter", "filters", "style", "blendTrans", and "Image()", "Play()" and "Apply()"?

Code: Select all
<script type="text/javascript">

var crossFadeDuration=3
//this variable is redundant because I can just input the number 3
//into the appropriate place further down the page, unless
//the author was trying to make a distinction between the two
//kinds of duration regarding blendTrans.  Why is it listed twice?
var Pic = new Array();

Pic[0]="blah1.jpg";
Pic[1]="blah2.jpg";
Pic[2]="blah3.jpg";
Pic[3]="blah4.jpg";
Pic[4]="blah5.jpg;

var j = 0;

var preLoad = new Array();
   
   for(i=0;i < pic.length;i++)
   {
   preLoad[i]= new Image();
   preLoad[i].src = Pic[i]
   }

function runSlideShow()
{
   if(document.all)
   {
   document.images.SlideShow.style.filter="blendTrans(duration=2)";
   document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
   document.images.SlideShow.filters.blendTrans.Apply();
   }

   document.images.SlideShow.src=preLoad[j].src;

   if(document.all)
   {
   document.images.SlideShow.filters.blendTrans.Play();
   }

   j = j+1;
   
   if(j>(pic.length-1)) j=0;
//this is the real subject of my confusion.[/b]
//I could also write this part as    if(j < (pic.length-5)) j=0    and the script will still work.
//I can see that it is good for j=0 to be false.  When j=0 is true, the script does not work.
//I can see that pic.length is the number of pics in the array, but why is it
//necessary for j=0 to be false?  Why is this stupid j=0 important!

setTimeout("runSlideShow()",5000);
}

</script>
daring_du
New User
New User
 
Posts: 5
Joined: Tue Jul 28, 2009 11:44 am
Blog: View Blog (0)


Re: stupid logic is not understanding me...

Post by tgoe on Tue Aug 04, 2009 12:24 am
([msg=27853]see Re: stupid logic is not understanding me...[/msg])

j=0 is never true :?
j is used as an index into preLoad. The if is to keep it in bounds.. resetting it to 0 makes the effect loop. And you probably mean Pic.
User avatar
tgoe
Contributor
Contributor
 
Posts: 639
Joined: Sun Sep 28, 2008 2:33 pm
Location: q3dm7
Blog: View Blog (0)


Re: stupid logic is not understanding me...

Post by daring_du on Tue Aug 04, 2009 11:19 am
([msg=27867]see Re: stupid logic is not understanding me...[/msg])

Hi tgoe,

Thanks for responding. You are right; I did mean "Pic. Thanks for spotting that, guy.

i hope you don't mind, but my screen name in real life is stupid_dummy_head so maybe you'll have a bit of mercy on me if I inquire a bit further as to what your explanation means in my simple language.

For example, I asked what the importance of j=0 is. While you have provided a valuable piece of information, that j=0 is NEVER true, I'm still not clear why it was important to the logic of the script to include a piece of information that is never meant to be true.

You say that the "if" is to keep "it" in bounds. Are you saying that the "if" is meant to keep the "j=0" in bounds? What are these "bounds" and HOW does J=0 keep "it" within those bounds?

I also don't understand what you mean by "resetting it". What was "it" reset from in the first place? Why does it need to be reset to create the effect loop?

I hope you won't think these questions are silly, as I feel they are relevant to my understanding the logic of this script. If I am asking the wrong questions please do let me know. Thanks again for you time.
daring_du
New User
New User
 
Posts: 5
Joined: Tue Jul 28, 2009 11:44 am
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests