content/hifi-content/james/debug/creator3.js
2022-02-13 23:57:50 +01:00

98 lines
No EOL
2.3 KiB
JavaScript

var basePosition = {
x: 0,
y: 0,
z: 0
};
var NUMBER_OF_BOXES = 4;
Agent.isAvatar = true;
function makeBoxes() {
var i;
for (i = 0; i < NUMBER_OF_BOXES; i++) {
createBox();
}
}
function createBox() {
var boxProps = {
dimensions: {
x: 1,
y: 1,
z: 1
},
color: {
red: 0,
green: 255,
blue: 0
},
type: 'Box',
name: 'TestBox',
position: {
x: basePosition.x + Math.random() * 5,
y: basePosition.y + Math.random() * 5,
z: basePosition.z + Math.random() * 5
}
}
print('JBP CREATING BOXX')
Entities.addEntity(boxProps)
}
var secondaryInit = false;
function deleteBoxes() {
if(secondaryInit===true){
return;
}
print('JBP DELETING BOXES FUNCTION ENTITYCOUNT: ' + EntityViewer.getOctreeElementsCount());
if (EntityViewer.getOctreeElementsCount() <= 1) {
print('JBP NOT ENOUGH TO START ')
Script.setTimeout(function() {
print('JBP WAITED A BIT TRY AGAIN')
deleteBoxes();
}, 1000)
return;
}
var results = Entities.findEntities(basePosition, 2000);
print('JBP FOUND ENTITIES::: ' + results.length)
results.forEach(function(r) {
var name = Entities.getEntityProperties(r, 'name').name;
print('JBP ENTITY NAME:: ' + name);
if (name === "TestBox") {
print('JBP WE HAVE A TEST BOX IN DELETE !!!' + r)
Entities.deleteEntity(r);
}
})
makeBoxes();
secondaryInit = true;
}
var initialized = false;
function update(deltaTime) {
if (!initialized) {
if (Entities.serversExist() && Entities.canRez()) {
Entities.setPacketsPerSecond(6000);
deleteBoxes()
initialized = true;
Script.update.disconnect(update);
}
return;
}
}
EntityViewer.setPosition({
x: 0,
y: 0,
z: 0
});
EntityViewer.setKeyholeRadius(60000);
Script.setInterval(function() {
EntityViewer.queryOctree();
}, 1000);
Script.update.connect(update);