{"id":2533,"date":"2014-11-18T09:11:54","date_gmt":"2014-11-18T09:11:54","guid":{"rendered":"https:\/\/www.mjtnet.com\/blog\/?p=2533"},"modified":"2014-11-18T09:11:54","modified_gmt":"2014-11-18T09:11:54","slug":"tip-remember-the-editor-is-a-debugger","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2014\/11\/18\/tip-remember-the-editor-is-a-debugger\/","title":{"rendered":"Tip: Remember &#8211; The Editor is a Debugger"},"content":{"rendered":"<p>When you run code in the Script Editor you are in fact running it inside a debugger.   <\/p>\n<p>This allows you to run code line by line or in chunks, and evaluate the values of your script variables in the watch list as you go.<\/p>\n<p>By default &#8211; after a first install &#8211; the debugger always runs scripts from the top &#8211; the very first line.  Just as would happen if you run the script some other way.  From top to bottom.<\/p>\n<p>But when you are debugging a script you often want to run a select number of lines or start debugging from a different line.  So, to do this, you can disable &#8220;Run From Top&#8221;.  This option is under the Tools menu.<\/p>\n<p>When &#8220;Run From Top&#8221; is disabled the macro will start from whichever is the current line &#8211; i.e. whichever line currently has the cursor on it.<\/p>\n<p>Recently in the forums two different people have had seemingly strange issues with scripts which turned out simply to be because they had this option turned off and weren&#8217;t running from the top.  In both cases they were getting errors because some variables they were referencing hadn&#8217;t yet been created!  The script had been started from a point after the variables were set.<\/p>\n<p>So, when running in the editor, if you&#8217;ve previously disabled &#8220;Run From Top&#8221;, and you want to run the script as normal, either reset this option or put the cursor on the first line before running.<\/p>\n<p>And if you see some seemingly strange behaviour which goes away when you run the script outside of the editor &#8211; it&#8217;s probably just because you haven&#8217;t run the script from the top!<\/p>\n<p>For more info on how to use the debugger please see:<\/p>\n<p><a href=\"http:\/\/help.mjtnet.com\/article\/7-using-the-debugger\">http:\/\/help.mjtnet.com\/article\/7-using-the-debugger<\/a><br \/>\n<a href=\"http:\/\/help.mjtnet.com\/article\/42-using-macro-schedulers-debugger-to-aid-script-creation\">http:\/\/help.mjtnet.com\/article\/42-using-macro-schedulers-debugger-to-aid-script-creation<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you run code in the Script Editor you are in fact running it inside a debugger. This allows you to run code line by line or in chunks, and evaluate the values of your script variables in the watch list as you go. By default &#8211; after a first install &#8211; the debugger always [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2533"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=2533"}],"version-history":[{"count":2,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2533\/revisions"}],"predecessor-version":[{"id":2535,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2533\/revisions\/2535"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=2533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=2533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=2533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}