2.0: Adoption Script=======================
2.1: What it DoesOr rather, what to make it do...
Javascript File:
1. Define how many variations there are.
2. Make an array and store the variations in it.
3. List the variations. List common variations more times than uncommon variations.
4. Make a function that chooses one of these variations randomly.
5. Output HTML and BBS(Forum) adoption code.
Adoption Page:
1. Link to the Javascript file.
2. Call the function.
3. Have a named <textarea> for the adoption codes to be put in.
2.2: Define VariationsFirst, make a Javascript file. You can do this in Dreamweaver or in Notepad. Save the file as a .js file, let's call it
egg1.js.
Let's start with some comments. If you put // at the start of a line, it makes the web browser ignore whatever you type. So let's make some comments. Let's say what it is, who edited it and what date you first made it (month and year is good).
- Code: Select all
//Solloby's Adoption Script
//Edited by [YOUR NAME], [Date]
Awesome. Now let's start with the code. How many variations do you want?
Dynos! uses 20 which allows for more rarities, but 10 is sufficient. If you regularly have more than 3 or 4 variations per egg then you should think about using 20. Fear not if you ever need more variations, it's very easy to change.
Let's put in our Javascript file how many we want.
- Code: Select all
var NumberOfVars = 10
There we go. We just made a new variable called NumberOfVars, and put the number 10 in it. Ok, let's make an array. An array is like a table of variables. It lets us store lots of values. I'm going to store the 'pointer' to the array in a variable called egg.
- Code: Select all
var egg = new BuildArray(NumberOfVars)
Lovely. Now let's put some variations in it. Let's assume we have 1 baby that grows into 2 different adults. Upload the baby to
Photobucket (if you use elsewhere just modify the output code to reflect this) and call it pet1.jpg. Upload it a second time and call it pet2.jpg. Later in the month, you can replace these images with the different adult stages. That's why we need two versions of the baby.
Here's the Javascript code to put our variations in the array. In this example, there is a 60% chance to adoption pet1 and 40% chance to adoption pet2, because pet1 appears in 6 out of 10 array cells (oh blah, I forget the proper jargon). If you want pet1 to be more common and pet2 to be more rare, put
- Code: Select all
//Variations
egg[1] = "pet1"
egg[2] = "pet1"
egg[3] = "pet1"
egg[4] = "pet1"
egg[5] = "pet1"
egg[6] = "pet1"
egg[7] = "pet2"
egg[8] = "pet2"
egg[9] = "pet2"
egg[10] = "pet2"
Let's make this array happen. Just copy-paste this randomness beneath your variation list to make magic happen.
- Code: Select all
function BuildArray(size){
this.length = size
for (var i = 1; i <= size; i++){
this[i] = null}
return this
}
Ok, so now we have an array with all our variations in it, and have even set the rarities!
2.3: Select Variation & Output Codes Now it's time to actually make the adoption occur. To do this, we need to select one of the 10 possible variations and output its code.
I have made a function called getEgg, which randomly chooses a variation and stores it in a new variable called rnd.
Notice our variable NumberOfVars has appeared.
- Code: Select all
function getEgg(frm) {
var rnd = Math.ceil(Math.random() * NumberOfVars)
Now it's time to output the adoption codes. This script was originally designed to be a random text generator and name generator, and when adapting it to adoptables I left the inclusion of forms, probably unnecessarily. What does this mean? This means that if you are hosting your adoptables site on
freewebs then it won't work until 7-8 days after you first sign up to a new account.
Ok, back to the code. frm stands for form. WordBox and WordBox2 are what I have called the textareas in my form. We'll revisit that later. Value is what we put in the textareas in the form. Something important to note is that the string (text characters) must be surrounded by " symbols. This means if we have a " symbol in the middle of our code, we need to put a \ symbol in front of it so that the web browser knows you want to include the " in the string. Otherwise it will think your string has ended, and won't understand what you've put afterwards!
- Code: Select all
frm.WordBox.value = "<a href=\"http://www.rainbow-muffin.org/dynos/index.html\"><img src=\"http://i434.photobucket.com/albums/qq67/Dynos01/dec08/" + egg[rnd] + ".jpg\"></a>"
frm.WordBox2.value = "[url=http://www.rainbow-muffin.org/dynos/index.html][img]http://i434.photobucket.com/albums/qq67/Dynos01/dec08/" + egg[rnd] + ".jpg[/img][/url]"
}
Replace the 2
http://www.rainbow-muffin.org/dynos/index.html with your own website's URL.
Next, replace the photobucket address to your photobucket's address. Don't link the image, just link up to the folder the image is in.
If you saved your images as .gif or .png instead of .jpg, change that as well. If your images are .bmp then you need to optimise them by saving them in one of the aforementioned formats, .bmp files are too unnecessarily large bandwidth-wise for the Internet.
Notice the egg[rnd] in the code above? egg is the name of our array, and rnd is the variable we are storing the randomly selected variation number in. So if our random generator picked the number 2, then egg[rnd] will point to egg[2] which is pet1, and the adoption code for pet1 will display.