From 14cdc5801e9f76e57e641ec60a7faf6289f4d265 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 2 Nov 2015 15:59:55 -0800 Subject: [PATCH] Fix updating of distance/high score --- examples/baseball/pitching.js | 53 ++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/examples/baseball/pitching.js b/examples/baseball/pitching.js index 47876aafdf..8710a33cce 100644 --- a/examples/baseball/pitching.js +++ b/examples/baseball/pitching.js @@ -2,9 +2,35 @@ print("Loading pitching"); //Script.include("../libraries/line.js"); Script.include("https://raw.githubusercontent.com/huffman/hifi/line-js/examples/libraries/line.js"); +// Return all entities with properties `properties` within radius `searchRadius` +function findEntities(properties, searchRadius) { + var entities = Entities.findEntities(MyAvatar.position, searchRadius); + var matchedEntities = []; + var keys = Object.keys(properties); + for (var i = 0; i < entities.length; ++i) { + var match = true; + var candidateProperties = Entities.getEntityProperties(entities[i], keys); + for (var key in properties) { + if (candidateProperties[key] != properties[key]) { + // This isn't a match, move to next entity + match = false; + break; + } + } + if (match) { + matchedEntities.push(entities[i]); + } + } + + return matchedEntities; +} + // These are hard-coded to the relevant entity IDs on the sport server -var DISTANCE_BILLBOARD_ENTITY_ID = "{faa88b15-5b85-408c-ae07-a31e5a5ca791}"; -var HIGH_SCORE_BILLBOARD_ENTITY_ID = "{5fe0daf5-3fc5-43e3-a4eb-81a8e840a52b}"; +var DISTANCE_BILLBOARD_NAME = "CurrentScore"; +var HIGH_SCORE_BILLBOARD_NAME = "HighScore"; +var DISTANCE_BILLBOARD_ENTITY_ID = findEntities({name: DISTANCE_BILLBOARD_NAME }, 1000)[0]; +var HIGH_SCORE_BILLBOARD_ENTITY_ID = findEntities({name: HIGH_SCORE_BILLBOARD_NAME }, 1000)[0]; +print("Distance: ", DISTANCE_BILLBOARD_ENTITY_ID) var METERS_TO_FEET = 3.28084; @@ -81,29 +107,6 @@ var DISTANCE_FROM_PLATE = PITCHING_MACHINE_PROPERTIES.position.z; var PITCH_RATE = 5000; -// Return all entities with properties `properties` within radius `searchRadius` -function findEntities(properties, searchRadius) { - var entities = Entities.findEntities(MyAvatar.position, searchRadius); - var matchedEntities = []; - var keys = Object.keys(properties); - for (var i = 0; i < entities.length; ++i) { - var match = true; - var candidateProperties = Entities.getEntityProperties(entities[i], keys); - for (var key in properties) { - if (candidateProperties[key] != properties[key]) { - // This isn't a match, move to next entity - match = false; - break; - } - } - if (match) { - matchedEntities.push(entities[i]); - } - } - - return matchedEntities; -} - getPitchingMachine = function() { // Search for pitching machine var entities = findEntities({ name: PITCHING_MACHINE_PROPERTIES.name }, 1000);