당신은 여기에 몇 가지 문제를 가지고, 당신이 무례하게 노력하지 않고 객체를 (이해하지 않는 것,하지만 당신은있어 가장 큰 하나 개의 존재 그들 waaay 잘못 사용).
var pLocation = [tickX, tickY]; // place this first to avoid undefined location
var player = {
weapon: stick, // stick without quotation marks is a variable, not a string, so this would be player.weapon = stick where stick = undefined variable.
speed: 3,
armor: cloth,
location: pLocation // since pLocation is defined after in your script i currently has no value, so location will be undefined.
}
//alternatively for pLocation
player.location = [tickX, tickY];
//Items
var stick = { stick: 1 }; // this creates an object called stick with a variable called stick with the value 1, so stick.stick = 1.
var cloth = { ClothArmor: 1 }; // this creates an object called cloth with a variable called ClothArmor with the value 1, so cloth.ClothArmor = 1.
그래서 player.weapon.stick을 호출하면 무기가 객체가 아니기 때문에 잘못되었습니다. 객체 내부의 변수입니다. player.weapon.stick을 원하면 다음을 사용해야합니다.
player = {
weapon: {
stick: 'Variable value'
}
}
당신은'tickX'와'tickY' 정의 된 일부 코드를 놓치고있어? – Andrei
'player'에서 사용하기 전에'stick'과'cloth'를 선언해야합니다. 'tickX'와'tickY'는 예제에서 정의되지 않았습니다. –