From 1ac1fcaf6958bfe380f96d605f2900a3aa091a50 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 16:17:54 -0700 Subject: [PATCH] Light switches work properly now; no extra lights --- examples/toys/lightSwitch.js | 18 +++++++++++------- unpublishedScripts/masterReset.js | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/toys/lightSwitch.js b/examples/toys/lightSwitch.js index 9a23a3b6d4..9494db4479 100644 --- a/examples/toys/lightSwitch.js +++ b/examples/toys/lightSwitch.js @@ -16,10 +16,11 @@ /*global LightSwitch */ (function () { + var _this; var utilitiesScript = Script.resolvePath("../libraries/utils.js"); Script.include(utilitiesScript); - LightSwitch = function () { + _this = this; this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); } @@ -38,23 +39,27 @@ toggleLights: function () { var lightData = getEntityCustomData(this.resetKey, this.entityID, {}); - var on = lightData.on; + var on = !lightData.on; var lightType = lightData.type; var lights = Entities.findEntities(this.position, 20); lights.forEach(function (light) { - var type = getEntityCustomData(this.resetKey, light, {}).type; - if (type === lightType) { + var type = getEntityCustomData(_this.resetKey, light, {}).type; + if (type === lightType && JSON.stringify(light) !== JSON.stringify(_this.entityID)) { Entities.editEntity(light, { visible: on }); + } }); - this.flipSwitch(); + Audio.playSound(this.switchSound, { + volume: 0.5, + position: this.position + }); setEntityCustomData(this.resetKey, this.entityID, { - on: !on + on: on, type: lightType, resetMe: true }); @@ -79,7 +84,6 @@ this.resetKey = "resetMe"; //The light switch is static, so just cache its position once this.position = Entities.getEntityProperties(this.entityID, "position").position; - this.lightType = getEntityCustomData(this.resetKey, this.entityID, {}).type; } }; diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 5f93218dcb..9f4543dc8f 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -218,7 +218,7 @@ function createLights() { var lightSwitchGarage = Entities.addEntity({ type: "Model", modelURL: modelURL, - name: "Garage", + name: "Light Switch Garage", script: scriptURL, position: { x: 545.62,