From 47d7e89699f084e810eaff75df3840bca09276c8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 27 Oct 2016 15:03:15 -0700 Subject: [PATCH] Update portal to ensure that properties exist --- .../DomainContent/Home/portal.js | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/portal.js b/unpublishedScripts/DomainContent/Home/portal.js index 0ea090a6f7..ea6241265c 100644 --- a/unpublishedScripts/DomainContent/Home/portal.js +++ b/unpublishedScripts/DomainContent/Home/portal.js @@ -1,40 +1,47 @@ (function(){ var teleport; var portalDestination; + var thisEntityID; function playSound() { - Audio.playSound(teleport, { volume: 0.40, localOnly: true }); + var properties = Entities.getEntityProperties(thisEntityID, 'position'); + if (properties) { + Audio.playSound(teleport, { position: properties.position, volume: 0.40, localOnly: true }); + } }; this.preload = function(entityID) { + thisEntityID = entityID; teleport = SoundCache.getSound("atp:/sounds/teleport.raw"); - var properties = Entities.getEntityProperties(entityID); - portalDestination = properties.userData; - - print("portal.js | The portal destination is " + portalDestination); + var properties = Entities.getEntityProperties(entityID, 'userData'); + if (properties) { + portalDestination = properties.userData; + print("portal.js | The portal destination is " + portalDestination); + } } this.enterEntity = function(entityID) { print("portal.js | enterEntity"); - var properties = Entities.getEntityProperties(entityID); // in case the userData/portalURL has changed - portalDestination = properties.userData; + var properties = Entities.getEntityProperties(entityID, 'userData'); // in case the userData/portalURL has changed + if (properties) { + portalDestination = properties.userData; - print("portal.js | enterEntity() .... The portal destination is " + portalDestination); + print("portal.js | enterEntity() .... The portal destination is " + portalDestination); - if (portalDestination.length > 0) { - if (portalDestination[0] == '/') { - print("Teleporting to " + portalDestination); - Window.location = portalDestination; + if (portalDestination.length > 0) { + if (portalDestination[0] == '/') { + print("Teleporting to " + portalDestination); + Window.location = portalDestination; + } else { + print("Teleporting to hifi://" + portalDestination); + Window.location = "hifi://" + portalDestination; + } } else { - print("Teleporting to hifi://" + portalDestination); - Window.location = "hifi://" + portalDestination; + location.goToEntry(); // going forward: no data means go to appropriate entry point } - } else { - location.goToEntry(); // going forward: no data means go to appropriate entry point } - }; this.leaveEntity = function(entityID) {