2016-10-08 5 views
-2

Ich bekomme einen Fehler, den ich nicht weiß, wie man "SyntaxError: missing} nach Funktion body" beheben kann. Aber ich habe keine Funktion namens Körper, Ich habe bereits versucht, jedes Wort Körper in meinem Skript zu ändern. Es sagt immer noch SyntaxError: fehlende} nach Funktion Körper. Mein Code:Javascript/html SyntaxError: fehlt} nach Funktion body

// This is where stuff in our game will happen: 
    var scene = new THREE.Scene(); 

    // This is what sees the stuff: 
    var aspect_ratio = window.innerWidth/window.innerHeight; 
    var camera = new THREE.PerspectiveCamera(75, aspect_ratio, 1, 10000); 
    camera.position.z = 500; 
    scene.add(camera); 

    // This will draw what the camera sees onto the screen: 
    var renderer = new THREE.WebGLRenderer({ antialias: true }); 
    renderer.setSize(window.innerWidth - 10, window.innerHeight - 25); 
    document.awesome.appendChild(renderer.domElement); 

    function maker (tx1, tx2, tx3, tx4, tx5, tx6, x, y, z, wide, height, back) { 
    var materials = [ 
    new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load(tx1)}), 
    new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load(tx2)}), 
    new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load(tx3)}), 
    new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load(tx4)}), 
    new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load(tx5)}), 
    new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load(tx6)}) 
    ]; 
    var geometry = new THREE.BoxBufferGeometry(wide, height, back); 
    mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials)); 
    return mesh; 
    } 
    function makeZombie(x, y, z) { 
    //zombie 
    head = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
     head.userData = {part: "head"}; 

     awesome = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
     awesome.userData = {part: "awesome"}; 
    //arms 
    arm_l = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/ zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
    arm_r = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
     arm_l.userData = {part: "arm_l"}; 
     arm_r.userData = {part: "arm_r"}; 
    //legs 
    leg_l = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
    leg_r = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
      leg_l.userData = {part: "leg_l"}; 
      leg_r.userData = {part: "leg_r"}; 
     var zombie = new THREE.Object3D(); 
    zombie.add(head); 
     zombie.add(awesome); 
     zombie.add(arm_r); 
     zombie.add(arm_l); 
     zombie.add(leg_l); 
     zombie.add(leg_r); 
     scene.add(zombie); 

     head.position.set(0, 100, 0); 
    arm_l.position.set(-58, 40, 40); 
    arm_r.position.set(58, 40, 40); 
    leg_l.position.set(-20, -120, 0); 
    leg_r.position.set(20, -120, 0); 
     arm_l.rotation.x = -Math.PI/2; 
     arm_r.rotation.x = -Math.PI/2; 
     arm_r.rotation.y = Math.PI; 

     zombie.position.set(x, y, z); 
     zombie.userData = {id: 1}; 
     mobs.push(zombie); 
     canttouchthis.push(zombie); 
    } 

    // make human 
    //head 
    human_head = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 

    human_awesome = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
    //arms 
    human_arm_l = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
    human_arm_r = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
    //legs 
    human_leg_l = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 
    human_leg_r = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 

    var human = new THREE.Object3D(); 
    var placeholder = new THREE.Object3D(); 
    var pos = new THREE.Vector3(); 

    human.add(human_head); 
    human.add(human_awesome); 
    human.add(human_arm_r); 
    human.add(human_arm_l); 
    human.add(human_leg_l); 
    human.add(human_leg_r); 
    placeholder.add(camera); 
    placeholder.add(human); 
    //placeholder.add(mobLookat); 
    scene.add(placeholder); 
    //scene.add(doghead); 

    human_head.position.set(0, 100, 0); 
    human_arm_l.position.set(-60, 5, 0); 
    human_arm_r.position.set(60, 5, 0); 
    human_arm_l.rotation.set(0, 0, -0.25); 
    human_arm_r.rotation.set(0, 0, 0.25); 
    human_leg_l.position.set(-20, -120, 0); 
    human_leg_r.position.set(20, -120, 0); 
    //mobLookat.position.set(0, 0, 0); 

    //sound 
    var bgSound = new Audio("sound/Bit Quest.ogg"); 
    bgSound.play(); 

    var moving_left = false; 
    var moving_right = false; 
    var moving_forward = false; 
    var moving_back = false; 
    var flying = false; 
    var gameOver = false; 
    var selectedclass; 
    var hasclass; 
    var spawners = []; 
    var mobs = []; 
    var canttouchthis = []; 
    var loader = new THREE.TextureLoader(); 
    //keypress event 
    document.addEventListener("keydown", function(event) { 
    if (event.keyCode == 37) { 
     placeholder.position.x = placeholder.position.x - 15; 
     walk(5, 30); 
     moving_left = true; 
     turn(); 
    } 
    if (event.keyCode == 39) { 
     placeholder.position.x = placeholder.position.x + 15; 
     walk(5, 30); 
     moving_right = true; 
     turn(); 
    } 
    if (event.keyCode == 40) { 
     placeholder.position.z = placeholder.position.z + 15; 
     walk(5, 30); 
     moving_back = true; 
     turn(); 
    } 
    if (event.keyCode == 38) { 
     placeholder.position.z = placeholder.position.z - 15; 
     walk(5, 30); 
     moving_forward = true; 
     turn(); 
    } 
    if (event.keyCode == 32) { 
     if (flying) { 
     placeholder.position.y = placeholder.position.y + 40; 
     } 
     else { 
     jump(); 
     } 

    } 
    if (event.keyCode == 16) { 
     if (flying) { 
      placeholder.position.y = placeholder.position.y - 40; 
     } 
    } 

    }); 

    document.addEventListener("keyup", function() { 
    human_arm_r.position.z = 0; 
    human_arm_l.position.z = 0; 
    human_leg_r.position.z = 0; 
    human_leg_l.position.z = 0; 
    moving_left = false; 
    moving_right = false; 
    moving_forward = false; 
    moving_back = false; 
    }); 
    function classselect() { 
    var input = prompt("Select your class, classes: warrior, archer, wizard", "Type here"); 
    if ((input != "warrior") && (input != "archer") && (input != "wizard")) { 
     alert("thats not a class..."); 
    } 
    else { 
     alert("Selected class '" + input + "' !"); 
     chat("Your now a " + input + " !") 
     selectedclass = input; 
     hasclass = true; 
     document.getElementById("classbutton").style.visibility = "hidden"; 
    } 
    } 

    Tree(500, 0, -75); 
    Tree(-500, 0, -75); 
    Tree(750, -1000, -75); 
    Tree(-750, -1000, -75); 
    Tree(0, -1200, -75); 
    Treasure(-750, -1050, -135); 
    function Tree(x, z, y) { 
    var top = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400); 

    trunk = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400); 
    top.position.y = 175; 
    trunk.add(top); 
    trunk.position.set(x, -75, z); 
    scene.add(trunk); 
    trunk.position.y = y; 

    } 
    function Treasure(x, z, y) { 

     chest = maker ("textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png" , "textures/mob/zombie/zombie_headleft.png", "textures/mob/zombie/zombie_headleft.png", 0, 0, 0, 200, 200, 400) 

    chest.position.set(x, -75, z); 
    scene.add(chest); 
    chest.position.y = y; 

    } 
    Flower(); 
    function Flower() { 
    for (i = 0; i < 2000; i++) { 
    var negative = Math.floor((Math.random() * 4) + 1); 
    var x = Math.floor((Math.random() * 5000) + -5000); 
    var z = Math.floor((Math.random() * 5000) + -5000); 
    if (negative == 1) { 
     x = -x; 
    } 
    if (negative == 2) { 
     z = -z; 
    } 
    if (negative == 3) { 
     x = -x; 
     z = -z; 
    } 
    var y = -225; 
    var color = Math.floor((Math.random() * 4) + 1); 
    if (color == 1) { 
     color = "textures/flower_pink.png" 
    } 
    if (color == 2) { 
     color = "textures/flower_blue.png" 
    } 
    if (color == 3) { 
     color = "textures/flower_purple.png" 
    }  
    if (color == 4) { 
     color = "textures/grass.png" 
    } 
    var petals = new THREE.Mesh(
     new THREE.PlaneGeometry(60,60), 
     new THREE.MeshBasicMaterial({map: new THREE.TextureLoader().load(color)}) 
    ); 
    scene.add(petals); 
    //stem.add(petals); 
    //stem.add(leaf); 
    petals.position.set(x, y, z); 
    petals.position.y = petals.position.y + 65; 
    //leaf.position.x = leaf.position.x + 10; 
    //leaf.position.z = leaf.position.z - 10; 
    } 

    place_spawner(0, 0, 0, 1, 7, 5); 
    function place_spawner (x, y, z, mob, rate, radius){ 
    var spawner = new THREE.Object3D(); 
    spawner.position.set(x, y, z); 
    spawner.userData = {mob:mob, rate:rate, radius:radius}; 
    spawners.push(spawner); 
    //console.log(spawners); 
    for (i = 0; i < spawners.length; i++) { 
     console.log(spawners[i].userData.radius); 
    } 
    } 
    window.setInterval(function() { 
    for (i = 0; i < spawners.length; i++) { 
     if (spawners[i].userData.mob == 1) { 
    makeZombie(spawners[i].position.x, spawners[i].position.y, spawners[i].position.z); 
     } 
     console.log(spawners[i]); 
    }  
    }, 10000) 
    //function dogAI() { 
    //console.log(mobLookat.position) 
    //doghead.lookAt(mobLookat.position); 
    //doghead.translateZ(2); 
    //doghead.position.y = -60; 

    //} 
    function mobAI_update() { 
    console.log(mobs); 
    for (i = 0; i < mobs.length; i++) { 
     if (mobs[i].userData.id == 1) { 
     mobs[i].lookAt(placeholder.position); 
     mobs[i].translateZ(10); 
     mobs[i].position.y = 0; 
     } 
    } 
    } 
    function makeLog() { 
     var holder = document.createElement("div"); 
     holder.style.height = "75px"; 
     holder.style.width = "450px"; 
     holder.style.overflow = "auto"; 
     holder.style.border = "1px solid #666"; 
     holder.style.backgroundColor = "#ccc"; 
     holder.style.padding = "8px"; 
     holder.style.position = "absolute"; 
     holder.style.bottom = "50px"; 
     holder.style.right = "20px"; 
     document.awesome.appendChild(holder); 

     return holder; 
    } 

    var log = makeLog(); 
    chat("start"); 

    function chat (message) { 
    if (message.charAt(0) == "/") { 
     command(message.substr(1)); 
    } 
    else { 
     var holder = document.createElement("div"); 
     holder.textContent = message; 
     log.appendChild(holder); 
    } 
    } 
    function command (command) { 
    chat(command); 
    if (command === "fly") { 
     chat("toggled flying"); 
     if (flying === false) { 
     flying = true; 
     } 
     else { 
     flying = false; 
     placeholder.position.y = 0; 
     } 

    } 
    if (command == "full") { 
     launchIntoFullscreen(document.documentElement); 
     chat("press 'esc' to exit") 
    } 
    } 
    function walk (speed, length) { 
    var position = Math.sin(clock.getElapsedTime()*speed)*length; 
    human_arm_r.position.z = position; 
    human_arm_l.position.z = -position; 
    human_leg_r.position.z = -position; 
    human_leg_l.position.z = position; 
    } 
    function turn() { 
    var direction = 0; 
    if (moving_forward) direction = Math.PI; 
    if (moving_back) direction = 0; 
    if (moving_left) direction = -Math.PI/2; 
    if (moving_right) direction = Math.PI/2; 
    spinHuman(direction); 
    } 
    function spinHuman (direction) { 
    new TWEEN. 
     Tween({y: human.rotation.y}). 
     to({y: direction}, 500). 
     onUpdate(function() { 
     human.rotation.y = this.y; 
     }). 
     start(); 
    } 
    function jump() { 
    new TWEEN 
     .Tween({jump: 0}) 
     .to({jump: Math.PI}, 600) 
     .onUpdate(function() { 
     placeholder.position.y = 250* Math.sin(this.jump); 
     }) 
     .start(); 
    } 

    function launchIntoFullscreen(element) { 
    if(element.requestFullscreen) { 
    element.requestFullscreen(); 
    } else if(element.mozRequestFullScreen) { 
    element.mozRequestFullScreen(); 
    } else if(element.webkitRequestFullscreen) { 
    element.webkitRequestFullscreen(); 
    } else if(element.msRequestFullscreen) { 
    element.msRequestFullscreen(); 
    } 

    // Now, show what the camera sees on the screen: 
    function update() { 
    requestAnimationFrame(update); 
    renderer.render(scene, camera); 
    mobAI_update(); 
    TWEEN.update();  
    } 
    update(); 

und meine html:

<html> 
    <head> 
     <title>evoker of light</title> 
    </head> 
    <style> 
     html, body { 
      margin:0; 
      padding:0; 
     } 
    </style> 
    <script type="text/javascript"> 
      function getValue(){ 
       var input = prompt("", "Type here"); 
       chat (input); 
      } 
      function submitchat(){ 
       chat(document.getElementById("chatfield").value) 
       document.getElementById("chatfield").value = ""; 
      } 
     </script> 
    <body> 
     <script src="game.js"></script> 
     <input type="button" style="position: absolute; top: 320px; width: 200px; left: 670px; height: 30px;" value="Select Class" onclick="classselect()" id="classbutton" onfocus="this.blur()"/> 
     <input type="text" style="position: absolute; top: 760px; width: 467px; right: 20px; height: 30px;" name="chat" id="chatfield"/> 
     <input type="button" style="position: absolute; top: 760px; width: 80px; right: 10px; height: 30px;" value="Submit" onclick="submitchat()" id="chatbutton"  onfocus="this.blur()"/> 
    </body> 
<script src="library/threejs/build/three.js"></script> 
<script src="http://gamingJS.com/Tween.js"></script> 
<script src="http://gamingJS.com/ChromeFixes.js"></script> 
<script src="http://gamingJS.com/Sounds.js"></script> 
</html> 

es ist sehr seltsam ... Dank!

+0

* "Aber ich habe keine Funktion namens Körper" * Der Körper einer Funktion ist das '{...}', das ihm folgt. Z. B. der Körper dieser Funktion: 'function foo() {alert (" bar "); } 'ist' {alert ("bar"); } '. –

+0

'Drücken Sie eine beliebige Taste, um fortzufahren' _Aber ich habe keine Taste Any! _ –

Antwort

0

Der Fehler wird verursacht, weil Sie nicht korrekt eingezogen haben und daher eine Klammer nicht schließen konnten. Es geschieht in der launchIntoFullscreen -function:

function launchIntoFullscreen(element) { 
if(element.requestFullscreen) { 
    element.requestFullscreen(); 
} else if(element.mozRequestFullScreen) { 
    element.mozRequestFullScreen(); 
} else if(element.webkitRequestFullscreen) { 
    element.webkitRequestFullscreen(); 
} else if(element.msRequestFullscreen) { 
    element.msRequestFullscreen(); 
} 

Sie können feststellen, die letzte Klammer nicht die Funktion Körper schließt, aber die else if statt. Nach Funktionskörper ist der Teil in den geschweiften Klammern {...} gesetzt.
Um dies zu beheben, müssen Sie am Ende eine schließende Klammer hinzufügen.

Korrekter Einzug hilft Ihnen, diese Fehler zu finden
Greets!

Verwandte Themen