{"id":711,"date":"2015-11-08T00:49:56","date_gmt":"2015-11-07T16:49:56","guid":{"rendered":"http:\/\/konsolscript.sourceforge.net\/web\/?p=711"},"modified":"2015-12-29T01:42:48","modified_gmt":"2015-12-28T17:42:48","slug":"understanding-konsolscript","status":"publish","type":"post","link":"http:\/\/konsolscript.sourceforge.net\/web\/2015\/11\/08\/understanding-konsolscript\/","title":{"rendered":"Tutorial 4: Understanding KonsolScript"},"content":{"rendered":"<p>This tutorial explains the sample code shown from <a href=\"http:\/\/konsolscript.sourceforge.net\/web\/2015\/10\/09\/hello-world\/\">Hello World<\/a> tutorial.<\/p>\n<h2>function main<\/h2>\n<p><strong><\/p>\n<pre>function main() {\r\n  \/\/more code to follow\r\n}<\/pre>\n<p><\/strong>All KonsolScript game should have this function called, <strong><code>main<\/code><\/strong>.<\/p>\n<p>This <code>main<\/code> function is the <em>first function to be executed<\/em> in KonsolScript.  Without <strong><code>function main<\/code><\/strong>, your code will not execute at all.<\/p>\n<p>So, what is to happen given that you have the sample code above?  Well, to simplify this demo, nothing else will happen for now unless the 2 other functions below will be executed.<\/p>\n<h2>function cleanrender<\/h2>\n<p><strong><\/p>\n<pre>function cleanrender() {\r\n  \/\/?\r\n}<\/pre>\n<p><\/strong>This function, called <strong><code>cleanrender<\/code><\/strong>, is one of the seven <strong>Event functions<\/strong> of KonsolScript.  An Event function is executed when the event happened.  For <code>cleanrender<\/code>, it is triggered each time the game screen is to be updated, like when you need to draw a car move across the screen.  <em>(More on Event functions below.)<\/em><\/p>\n<p>But as the sample code demonstrates, there&#8217;s nothing actually happening there right now.  As the function&#8217;s name suggests, it <em>cleans<\/em> the screen.<\/p>\n<h2>function mousemove<\/h2>\n<p><strong><\/p>\n<pre>function mousemove() {\r\n  Screen:PrintString(\"hi, I'm KonsolScript!\")\r\n}<\/pre>\n<p><\/strong>This last function from the sample code is another one of the seven <em>Event functions<\/em>.  As stated above, this function is executed if the event happens.  From the name alone, it means that this part of the code will be executed when the mouse is moved along the screen.<\/p>\n<p>From the demo, you will see a text saying, &#8220;<strong>hi, I&#8217;m KonsolScript!<\/strong>&#8220;, every time the mouse is <em>moving<\/em>.  This is printed on the screen via the command <strong><code>Screen:PrintString<\/code><\/strong> &#8212; you can change the text between the double quotes if you want. \ud83d\ude42<\/p>\n<p>The text disappears from the screen when the moving stops.  The reason it disappears is because the function <code>cleanrender<\/code> is triggered &#8212; meaning, <em>the text on the screen was cleaned up<\/em>.<\/p>\n<h2>Event functions<\/h2>\n<p><strong><\/p>\n<pre>function mousedown() {\r\n  \/\/\r\n}\r\n\r\nfunction mouseup() {\r\n  \/\/\r\n}\r\n\r\nfunction keydown() {\r\n  \/\/\r\n}\r\n\r\nfunction keyup() {\r\n  \/\/\r\n}\r\n\r\nfunction render() {\r\n  \/\/\r\n}<\/pre>\n<p><\/strong>Above are the 5 remaining Event functions in KonsolScript that were not included in the sample code to simplify the demo.  Above functions are triggered, when the <em>mouse<\/em> or a <em>key on the keyboard<\/em> is <em>pressed down<\/em>, or <em>unpressed<\/em>.  The function <strong><code>render<\/code><\/strong> is the same with function <code>cleanrender<\/code>, but it does <strong>not<\/strong> clean the screen.  If you are trying to optimize the framerate of your game, you need to use <code>render<\/code> over <code>cleanrender<\/code>.<\/p>\n<p>If you are wondering which among <code>render<\/code> and <code>cleanrender<\/code> will be executed when both functions are inside your code,  it&#8217;s the <code>render<\/code> function &#8212; <em>the <code>cleanrender<\/code> function will be ignored<\/em>.<\/p>\n<p>So, what else is there to know?  In the <a href=\"http:\/\/konsolscript.sourceforge.net\/web\/2015\/12\/29\/exploring-konsolscript\/\">next tutorial<\/a>, we will explore the log file that was generated when you executed the sample code! \ud83d\ude09<\/p>\n<p>~creek23<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial explains the sample code shown from Hello World tutorial. function main function main() { \/\/more code to follow } All KonsolScript game should have this function called, main. This main function is the first function to be executed in KonsolScript. Without function main, your code will not execute at all. So, what is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/posts\/711"}],"collection":[{"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/comments?post=711"}],"version-history":[{"count":7,"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/posts\/711\/revisions"}],"predecessor-version":[{"id":714,"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/posts\/711\/revisions\/714"}],"wp:attachment":[{"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/media?parent=711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/categories?post=711"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/konsolscript.sourceforge.net\/web\/wp-json\/wp\/v2\/tags?post=711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}