Forum Settings
       
Reply To Thread

Code for making an ezboard rotating on refresh sig imageFollow

#1 Mar 10 2004 at 8:21 AM Rating: Excellent
Avatar
******
29,919 posts
<script>
currentIndx=0;
SigImages=new Array();

var generatornum=Math.random();//Turn on the random number generator

var maxnumber=4; //Make this number the number of sig images you have

maxnumber = maxnumber - 1;
var randomnum=Math.round(generatornum*maxnumber);//make random number
randomnum = randomnum + 1;
//document.write(randomnum);
loadimage = "SigImages[" + randomnum + "]"
//document.write(loadimage);

var loadnew = loadimage ;

//Put your magelo link in below.
document.write("<a href='https://everquest.allakhazam.com/db/journal2.html?user=4491'><img src='");


//Make an IF section for each image


if(randomnum == 1){document.write("http://home.houston.rr.com/acep38/images/sig1.jpg")
;
}


if(randomnum == 2){document.write("http://www.strike9.com/file.ashx?path=%5cpiercet%5cfullsize%5csnailatar.jpg")
;
}



if(randomnum == 3){document.write("http://www.strike9.com/file.ashx?path=%5cpiercet%5cfullsize%5c75pix.jpg")
;
}



if(randomnum == 4){document.write("https://everquest.allakhazam.com/uf/Kaolian/test.jpg")
;
}


//Change the alt text if you want
document.write("' border=0 alt='Kaolian Drachensborn. Ranger, part time Emperor. Tech support to the stars.' ></a>");

if(randomnum == 1){document.write("<br> Kaolian Drachensborn, lvl 52 Half elf ranger, Bertoxxulous, Epic")
;
}

if(randomnum == 2){document.write("<br> Kaoliantoo Drachensborn, lvl 30 Half elf ranger, Firiona Vie, FOS")
;
}

if(randomnum == 3){document.write("<br> Kaolian Drachensborn, SWG Human ranger, Radient, FOH")
;
}

if(randomnum == 4){document.write("<br> This space for rent.")
;
}

</script>




Edited, Wed Mar 10 08:20:47 2004 by Kaolian

Edited, Sat Mar 13 11:29:43 2004 by Kaolian
____________________________
Arch Duke Kaolian Drachensborn, lvl 95 Ranger, Unrest Server
Tech support forum | FAQ (Support) | Mobile Zam: http://m.zam.com (Premium only)
Forum Rules
#2 Mar 13 2004 at 11:32 AM Rating: Excellent
Avatar
******
29,919 posts
Text only code:

<script>
currentIndx=0;
SigImages=new Array();

var generatornum=Math.random();//Turn on the random number generator

var maxnumber=4; //Make this number the number of sig images you have

maxnumber = maxnumber - 1;
var randomnum=Math.round(generatornum*maxnumber);//make random number
randomnum = randomnum + 1;
//document.write(randomnum);
loadimage = "SigImages[" + randomnum + "]"
//document.write(loadimage);

var loadnew = loadimage ;


//Edit between the " " with any valid html text, including links, tables, etc.
if(randomnum == 1){document.write("<br> Kaolian Drachensborn, lvl 52 Half elf ranger, Bertoxxulous, Epic")
;
}

if(randomnum == 2){document.write("<br> Kaoliantoo Drachensborn, lvl 30 Half elf ranger, Firiona Vie, FOS")
;
}

if(randomnum == 3){document.write("<br> Kaolian Drachensborn, SWG Human ranger, Radient, FOH")
;
}

if(randomnum == 4){document.write("<br> This space for rent.")
;
}

</script>
#3 Mar 17 2004 at 8:50 AM Rating: Excellent
**
385 posts
A few comments on your script.

First, this can actually be used on any board that will allow any HTML tags in the sig block. For security reasons, many boards will block script tags, though. I've never thought to test it on EZBoard.

Quote:
var generatornum=Math.random();//Turn on the random number generator 
 
var maxnumber=4; //Make this number the number of sig images you have 
 
maxnumber = maxnumber - 1;  
var randomnum=Math.round(generatornum*maxnumber);//make random number 
randomnum = randomnum + 1; 


This is more a nitpick than anything else, but I had to stare at these calculations a while to figure out what you were doing and why. I finally got it, but it causes a few issues. The big one that jumps out at me is that the first and last images the user enters will be displayed half as often as the images inbetween. Using your example of 4 images, over time, image 1 and image 4 will each be displayed around 17% of the time, while image 2 and image 3 will be displayed 33% of the time. (This is due to rounding; 0-0.499... rounds to zero, which means image 1, whereas 0.5-1.499... rounds to 1, which is image 2.) The solution is to create a do-while loop and use Math.ceil, as follows:

do{ randomnum = Math.ceil(Math.random()*maxnumber); } while (randomnum == 0); 


This guarantees you an integer between 1 and maxnumber without having to use a placeholder variable or modify maxnumber at all. There is an equal chance of getting any of the numbers.

Second thing I would suggest is to make placeholder variables to hold the link and tag line, then use a single document.write to spit it all out. A switch statement would make the code easier to read and modify for a non-programmer.

You also apparently have a few vestigial lines from an earlier incarnation of the script that uses arrays and image preloading. I've removed those.

Finally, I renamed a couple of things to make it easier to read.

The finished script would look something like this:

Quote:
<script> 
// Declare some variables.  Don't modify anything in this section. 
var SelectedSig, ImageLink, Tagline, AltText; 
 
 
/***************************** 
Only modify the values after this marker 
****************************/ 
 
//Make this number the number of sig images you have 
var NumberOfSigs = 4;  
 
//Put your Magelo or Allakhazam profile link in below. 
var ProfileLink = "https://everquest.allakhazam.com/db/journal2.html?user=4491"; 
 
//Don't modify this next line.  It's to select a random image to display. 
do{ SelectedSig = Math.ceil(Math.random()*NumberOfSigs); } while (SelectedSig == 0);  
 
/* 
Make a new CASE block for each sig you have.   
Just copy and paste the lines, increment the number on the CASE. 
Don't touch the Switch line, and be sure there's a break at the end of each case. 
 
ImageLink is the link to the image, starting with http://.  This is required. 
 
AltText is the text the browser should display in place of the image if the  
image can't load.  You can leave this blank. 
 
Tagline is a line of text you want to appear under the image. 
*/ 
 
switch (SelectedSig) 
{ 
case 1: 
	ImageLink = "http://home.houston.rr.com/acep38/images/sig1.jpg"; 
	AltText = "Kaolian Drachensborn. Ranger, part time Emperor. Tech support to the stars."; 
	Tagline = "Kaolian Drachensborn, lvl 52 Half elf ranger, Bertoxxulous, Epic"; 
	break; 
case 2: 
	ImageLink = "http://www.strike9.com/file.ashx?path=%5cpiercet%5cfullsize%5csnailatar.jpg"; 
	AltText = "Kaolian Drachensborn. Ranger, part time Emperor. Tech support to the stars."; 
	Tagline = "Kaoliantoo Drachensborn, lvl 30 Half elf ranger, Firiona Vie, FOS"; 
	break; 
case 3: 
	ImageLink = "http://www.strike9.com/file.ashx?path=%5cpiercet%5cfullsize%5c75pix.jpg"; 
	AltText = "Kaolian Drachensborn. Ranger, part time Emperor. Tech support to the stars."; 
	Tagline = "Kaolian Drachensborn, SWG Human ranger, Radient, FOH"; 
	break; 
case 4: 
	ImageLink = "https://everquest.allakhazam.com/uf/Kaolian/test.jpg"; 
	AltText = "Kaolian Drachensborn. Ranger, part time Emperor. Tech support to the stars."; 
	Tagline = "This space for rent."; 
	break; 
} 
 
/***************************** 
Do not modify anything below here 
****************************/ 
 
// Write out the entire link. 
document.write("<a href='" + ProfileLink + "'><img src='"  
		+ ImageLink + "' border=0 alt='" + AltText  
		+ "' ></a><br>\n" +  Tagline + "\n"); 
</script> 



Edited to fix the errors Kaolian pointed out in the JavaScript.

Edited, Mon Mar 22 00:53:47 2004 by KyrosKrane
____________________________
--
Sir KyrosKrane Sylvanblade
Luclin (Veeshan) Server
Lord, Lightbringer, and Redeemer in the service of Erollisi Marr
Master Artisan (300 + GM Trophy in All)
Master Fisherman (200 + 5%) and maybe Master Drunk (2xx + 20%, too drunk to tell!)
#4 Mar 17 2004 at 9:33 AM Rating: Excellent
Avatar
******
29,919 posts
I'll try that out, thank's for posting that! (I had noticed that image 4 specifically was not showing up nearly as much)


Edit: tested the script over at ezboards. It was a bit too long to fit in the allocated character numbers, SO I went in and culled alot of the comments. I'm usually all for comments, but the space limits make them problematic. Also added a ) to the end of the document. wrte statement at the end, and changed SigList to Siglist, as it was lowercase everywhere except that one declaration. Added a few semi colans too, just to be safe. Good use of Case blocks. I'll keep that in mind next time I make something. Thanks again!

<script>
// Declare some variables. Don't modify this section.
var SelectedSig, ImageLink, Tagline;


/***
Only modify values after this marker
***/

//number sig images you have
var NumberOfSigs = 4;

//Put your profile link here.
var ProfileLink = "https://everquest.allakhazam.com/db/journal2.html?user=4491"

//Don't modify this next line.
do{ SelectedSig = Math.ceil(Math.random()*NumberOfSigs); } while (SelectedSig == 0);

/*
Make a new CASE block for each sig.
*/

switch (SelectedSig)
{
case 1:
ImageLink = "http://home.houston.rr.com/acep38/images/sig1.jpg";
AltText = "Kaolian Drachensborn. Ranger, part time Emperor. Tech support to the stars.";
Tagline = "Kaolian Drachensborn, lvl 52 Half elf ranger, Bertoxxulous, Epic";
break;
case 2:
ImageLink = "http://www.strike9.com/file.ashx?path=%5cpiercet%5cfullsize%5csnailatar.jpg";
AltText = "Beware of Wombats and giant yellow Snails!";
Tagline = "Kaoliantoo Drachensborn, lvl 30 Half elf ranger, Firiona Vie, FOS";
break;
case 3:
ImageLink = "http://www.strike9.com/file.ashx?path=%5cpiercet%5cfullsize%5c75pix.jpg";
AltText = "Kaolian Drachensborn. Ranger, part time Emperor. Tech support to the stars.";
Tagline = "Kaolian Drachensborn, SWG Human ranger, Radient, FOH";
break;
case 4:
ImageLink = "https://everquest.allakhazam.com/uf/Kaolian/test.jpg";
AltText = "I should really put another sig here...";
Tagline = "This space for rent.";
break;
}

/***
Do not modify anything below here
***/

// Write out the entire link.
document.write("<a href='" + ProfileLink + "'><img src='"
+ ImageLink + "' border=0 alt='" + AltText
+ "' ></a><br>\n" + Tagline + "\n");
</script>



Edited, Wed Mar 17 10:01:43 2004 by Kaolian

Edited, Wed Mar 17 14:31:48 2004 by Kaolian
#5 Mar 18 2004 at 3:18 AM Rating: Good
**
385 posts
Quote:
Also added a ) to the end of the document. wrte statement at the end


Gah, I knew I'd miss something. I should have loaded it into my browser and tested it.

Anywho. What's a SigList/Siglist? I don't see a reference to that anywhere.

JavaScript is pretty flexible on semicolons. Strictly speaking, they're only required if you want to put multiple statements on one line. However, it's good programming practice to put one at the end of each line. (Bad Kyros, forgetting semicolons! Bad! No cookie! Smiley: disappointed )

I also tend to over-comment my code so that a stranger reading it has an idea of what I'm doing. You can safely remove all the comments if you need to stay under their size limits.

There's also a lot of extra white space in my version, and many of the statements can be combined on one line, to save a few extra bytes here and there. That would kill readability and made debugging harder, though.
____________________________
--
Sir KyrosKrane Sylvanblade
Luclin (Veeshan) Server
Lord, Lightbringer, and Redeemer in the service of Erollisi Marr
Master Artisan (300 + GM Trophy in All)
Master Fisherman (200 + 5%) and maybe Master Drunk (2xx + 20%, too drunk to tell!)
#6 Mar 19 2004 at 6:21 AM Rating: Excellent
Avatar
******
29,919 posts
http://home.houston.rr.com/acep38/Siggenerator.htm

I turned your code into an auto generatable version. Take it for a spin if you like.

Dunno why I said siglist. I honestly don't have a clue where that even came from. The one with the error is TagLine In one spot the variable is Tagline, not TagLine, and it seems to be case sensitive. the one in Line 3 is the one with the lowercase l.
#7 Mar 21 2004 at 3:21 AM Rating: Good
**
385 posts
Correction noted. See what happens when you don't test your code? :( Fixed my post above again.
____________________________
--
Sir KyrosKrane Sylvanblade
Luclin (Veeshan) Server
Lord, Lightbringer, and Redeemer in the service of Erollisi Marr
Master Artisan (300 + GM Trophy in All)
Master Fisherman (200 + 5%) and maybe Master Drunk (2xx + 20%, too drunk to tell!)
Reply To Thread

Colors Smileys Quote OriginalQuote Checked Help

 

Recent Visitors: 115 All times are in CST
Anonymous Guests (115)