あなたはここにいくつかの問題を持っている、あなたは失礼なことをしようとしていないオブジェクトを(理解していないようですが、あなたはしている最大の一つでありますそれらを使用して間違って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'は例では定義されていません。 –