I am trying to make function which accepts 7 digit code (at minimum) and then loads images/elements of character thus creating a character from code.
I wrote this code:
<script type="text/javascript">
var skins = [];
skins["w"] = "http://example.com/char_elements/base.png";
var eyes = [];
eyes["b"] = "http://example.com/char_elements/eyes/blue.png";
eyes["g"] = "http://example.com/char_elements/eyes/green.png";
eyes["r"] = "http://example.com/char_elements/eyes/red.png";
var hair = [];
hair["b"] = "http://example.com/char_elements/hair/black.png";
hair["w"] = "http://example.com/char_elements/hair/blond.png";
hair["s"] = "http://example.com/char_elements/hair/brown.png";
var mouth = [];
mouth["h"] = "http://example.com/char_elements/mouth/happy.png";
var pants = [];
pants["s"] = "http://example.com/char_elements/pants/shorts.png";
var shoes = [];
shoes["b"] = "http://example.com/char_elements/shoes/black.png";
var torso = [];
torso["s"] = "http://example.com/char_elements/torso/shirt.png"
function LoadChar(code){
var data = code.split(/(?=[a-z])/i);
var skins = [skins[data[0]], eyes[data[1]], hair[data[2]], mouth[data[3]], pants[data[4]], shoes[data[5]], torso[data[6]]];
document.getElementById("out").innerHTML = skins.toString();
}
</script>
<div id="out"></div>
However, when I call LoadChar("wgbhsbs");
It thorws me "Cannot read property 'w' of undefined"
I am still new to Arrays in JS, so I am sure I am making some simple Syntax error or doing something a bit wrong.
So what this does is:
1) Accepts code and splits it into 7 elements (always 7, nothing else) stores it in "data" variable as array. 2) Builds "skins" array by loading: skin[number from code] and same for other elements. 3) For testing purposes I am trying to output skins array, but it stops at step 2.
Is there any explanation to this?
skinstwice, once outside the function, and then a local variable inside the function with the same name, that doesn't have awproperty