{"id":29,"date":"2022-02-03T20:03:59","date_gmt":"2022-02-03T20:03:59","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/tapiaang\/?p=29"},"modified":"2022-02-03T20:03:59","modified_gmt":"2022-02-03T20:03:59","slug":"blog-post-5-a-noobs-confusion-with-async-and-await","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/tapiaang\/2022\/02\/03\/blog-post-5-a-noobs-confusion-with-async-and-await\/","title":{"rendered":"Blog Post 5 &#8211; A noob&#8217;s confusion with async and await"},"content":{"rendered":"\n<p>the sample code that microsoft supplies with their speech recognition unity example has asynchronous methods in a class that uses a button to call the voice record method and displays what the user says in a text ui element.<\/p>\n\n\n\n<p>for someone who has not worked with async methods besides one week in my web dev class, it makes sense when it is working. &#8220;sure sure, call that method and it changes the text once it gathers what the user says in the microphone.&#8221; but what  if i want to return a value instead of modifying a variable?<\/p>\n\n\n\n<p>at first i didn&#8217;t think you could return a value, but then i found a <a href=\"https:\/\/www.youtube.com\/watch?v=2moh18sh5p4\">video<\/a> that did a pretty good job of explaining it abstractly and with an example. you can return tasks i guess, and then using await is how you can get the value out of that. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"347\" height=\"19\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5159\/files\/2022\/02\/2022-02-03-11_55_07-from-microphone-Microsoft-Visual-Studio.png\" alt=\"\" class=\"wp-image-30\" srcset=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5159\/files\/2022\/02\/2022-02-03-11_55_07-from-microphone-Microsoft-Visual-Studio.png 347w, https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5159\/files\/2022\/02\/2022-02-03-11_55_07-from-microphone-Microsoft-Visual-Studio-300x16.png 300w\" sizes=\"auto, (max-width: 347px) 85vw, 347px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"279\" height=\"19\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5159\/files\/2022\/02\/2022-02-03-11_55_34-from-microphone-Microsoft-Visual-Studio.png\" alt=\"\" class=\"wp-image-31\" \/><\/figure>\n\n\n\n<p>startasync calls voicerecord in my script, but the idea still holds. in my example, i&#8217;m trying to send the voice recognition script a string, compare it to what the user said, and return true or false based on that comparison. without await in the statement, i was getting an error that task&lt;bool&gt; could not be converted to bool. <\/p>\n\n\n\n<p>it&#8217;s a bit confusing at first, but once i got it working it seemed fine, and can be called from any script without any button or text connected to it. now i just need to see if it works in our game. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>the sample code that microsoft supplies with their speech recognition unity example has asynchronous methods in a class that uses a button to call the voice record method and displays what the user says in a text ui element. for someone who has not worked with async methods besides one week in my web dev &hellip; <a href=\"https:\/\/blogs.oregonstate.edu\/tapiaang\/2022\/02\/03\/blog-post-5-a-noobs-confusion-with-async-and-await\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Blog Post 5 &#8211; A noob&#8217;s confusion with async and await&#8221;<\/span><\/a><\/p>\n","protected":false},"author":12001,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/users\/12001"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":1,"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":32,"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/posts\/29\/revisions\/32"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/tapiaang\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}