json - how to invoke javascript function and variable from another javascript file -


i'm building application check if users follow instruction provided take photo , match facial recognition. have 8 instructions users such checking whether smiling while taking photo, since our facial recognition achieved through online api 'skybiometry'. have according value json value follows, in html file, need call verifyface() function , message , result variable in javascript file if result unsuccessful. call function verifyface(); , followed result; , message;. code not working.

function valuestocheck(){     msgs = msgs();      randommsg = randommsg();     if (randommsg == msgs[0] || randommsg == msgs[1]){       var check = photos[0].tags[0].attributes[0].glasses[0];     } else if (randommsg == msgs[2] || randommsg == msgs[3]) {       var check = photos[0].tags[0].attributes[0].smiling[0];     } else if (randommsg == msgs[4] || randommsg == msgs[5]) {       var check = photos[0].tags[0].attributes[0].lips[0];     } else if (randommsg == msgs[6] || randommsg == msgs[7]) {       var check = photos[0].tags[0].attributes[0].eyes[0];     }     check = "facesdet." + check;     return check; }  var result = "unsuccessful"; var message = "you didn't follow instruction, please try again.";  function verifyface(){     msgs = msgs();      randommsg = randommsg();     check = valuestocheck();     var value = check + ".value";     var confidence = check + ".confidence";     if (randommsg == msgs[0] && value == true && confidence >= 50){       console("users followed instruction!");     } else {       result;       message;     }       if (randommsg == msgs[1] && value == false && confidence < 50){       console("users followed instruction!");     } else {       result;       message;     }      if (randommsg == msgs[2] && value == true && confidence >= 50){       console("users followed instruction!");     } else {       result;       message;     }  } 

below json output 'skybiometry':

{ "photos" : [     {         "url" : "http://tinyurl.com/673cksr",         "pid" : "f@0c95576847e9cd7123f1e304476b59ae_59ec9bb2ad15f",         "width" : 375,         "height" : 409,         "tags" : [             {                 "tid" : "temp_f@0c95576847e9cd7123f1e304b1dcbe53_59ec9bb2ad15f_56.53_40.83_0_1",                 "recognizable" : true,                 "confirmed" : false,                 "manual" : false,                 "width" : 30.67,                 "height" : 28.12,                 "center" : { "x" : 56.53, "y" : 40.83},                 "eye_left" : { "x" : 66.93, "y" : 33.99},                 "eye_right" : { "x" : 51.73, "y" : 33.99},                 "yaw" : -16,                 "roll" : 0,                 "pitch" : 0,                 "attributes" : {                     "face" : { "value" : "true", "confidence" : 82 },                     "gender" : { "value" : "female", "confidence" : 80 },                     "glasses":{"value" : "true", "confidence" : 100},                     "dark_glasses":{"value" : "true", "confidence" : 72},                     "smiling":{"value" : "false", "confidence" : 35}                 }             }         ]     } ], "status" : "success", "usage" : {     "used" : 1,     "remaining" : 99,     "limit" : 100,     "reset_time_text" : "fri, 21 september 2012 12:57:19 +0000",     "reset_time" : 1348232239 } } 

i don't think these lines:

msgs = msgs();  randommsg = randommsg(); 

are doing want, since said variables , not functions.

if msgs , randommsg global variables, can omit lines , use msgs , randommsg in functions.

another possibility, if, example, want insure functions don't change globals this:

var msgs      = window.msgs      || ''; var randommsg = window.randommsg || ''; 

which makes copy of globasl locals (or empty string if don't exist).

also these lines:

result; message; 

have no visible effect. want put them someplace on page or like:

alert('result: ' + result + ", message = " + message); 

at least?


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -