고유 한 속성을 가진 지형 발생기를 작성하고 있지만 범위 문제로 인해 어려움을 겪고 있습니다. 이것은 멍청한 놈 문제처럼 보일지도 모르지만 나는 그 아카이브를 수색 했어. 그리고 나에게 그 문제를 밝히는 어떤 것도 발견하지 못했다. 함수 내에 함수가 있습니다. (이 객체 패러다임에 익숙하지 않습니다.) 다른 객체의 내부 함수에 액세스하려고합니다. 코드에서 "Uncaught TypeError : undefined waxy.js의 속성 'width'을 읽을 수 없습니다 : 45 BoundingBox waxy.js : 45 (익명 함수)"라는 오류 메시지가 Chrome 콘솔에 표시됩니다. 오류는 마지막 행에서 ' bounds.width '이 함수를 노출해야하지만 어떻게해야합니까?자바 스크립트가 정의되지 않은 'width'속성을 읽을 수 없습니다.
//A wrapper class for an int triple
var Point = (function(dimensions) {
var x = function() {return dimensions.x || 0}
var y = function() {return dimensions.y || 0}
var z = function() {return dimensions.z || 0}
})//end Point
//a working set, rectangular prism
var BoundingBox = (function(dimensions) {
var lowerBound = function(){return Point(dimensions[0])}
var upperBound = function(){return Point({x:dimensions[1].x + dimensions[0].x, y:dimensions[1].y + dimensions[0].y, z:dimensions[1].z + dimensions[0].z})}
var width = function() {return this.upperBound.x - this.lowerBound.x}
var depth = function() {return this.upperBound.y - this.lowerBound.y}
var height = function() {return this.upperBound.z - this.lowerBound.z}
var contains = function(cOffset, cDims) {
return !((cOffset.x < this.lowerBound.x || cOffset.y < this.lowerBound.y || cOffset.z < this.lowerBound.z) ||
(cDims.x > this.upperBound.x || cDims.y > this.upperBound.y || cDims.z > this.upperBound.z))
}
var intersects = function(iOffset, iDims) {
return ((iOffset.x >= this.lowerBound.x && iOffset.y >= this.lowerBound.y && iOffset.z >= this.lowerBound.z) ||
(iDims.x <= this.upperBound.x && iDims.y <= this.upperBound.y && iDims.z <= this.upperBound.z))
}
var iterator = function() { return BoxIterator(this) }
})//end BoundingBox
//stores terrain value for each x,y,z in a working set (BoundingBox)
//each property in a list has a value for each node in working set
var MapData = (function(workingSet, properties) {
var bounds = workingSet
var props = properties
var data = []
//make sure property name is spelled right
var map = function(x,y,z,property) {return data[x,y,z,props.indexOf(property)] }
var terrainMap = function(x,y,z) {return map(x,y,z,'terrain')}
//!isEmpty equiv. isTerrain
var isEmpty = function(x,y,z) {return map(x,y,z,'terrain')===0}
var tempMap = function(x,y,z){return map(x,y,z,'temperature')}
})//end MapData
//create a sheet of terrain drops
var DropSheet = (function(opts) {
var depth = opts.depth
var width = opts.width
var rate = opts.rate
var generate = function() {
for(var i = 0; i<depth * width; i++) {
drop[i] = Math.random() <= rate
}
return drop
}
})//end DropSheet
//simulated annealing
var WaxyGenerator = (function(opts) {
var initialTemp = opts.initialTemp || 1.0
var fillPercent = opts.fillPercent || 0.35
var conductivity = opts.conductivity || 0.04
var freezing = opts.freezing || 0.1
var floorTemp = opts.floorTemp || 0.0
var bounds = opts.bounds || BoundingBox([{x:0,y:0,z:0}, {x:80,y:80,z:80}])
//each property in propertyList has its own map data
var propertyList = opts.propertyList || ['terrain', 'temperature']
var materials = opts.materials || ['grass', 'dirt', 'grass_dirt', 'obsidian', 'whitewool', 'brick']
//map of data
var data = MapData(bounds, propertyList)
//create a drop sheet
var sheetMaker=DropSheet({width:bounds.width, depth:bounds.depth, rate:fillPercent})
//some functions...
}
실행할 수 있도록 함수에 대한 트리거를 만들고 – Adidi