{"assets":[],"author_link":"author\/yourlocalfaxmachine\/","author_name":"YourLocalFax","cat":"LD - Misc","categories":["LD - Misc"],"comments":[],"epoch":1420930260,"event":"","likes":5,"metadata":{"p_key":"82592","p_author":"YourLocalFax","p_authorkey":"0","p_urlkey":"293324","p_title":"Sharpening My Tools\u2026","p_cat":"LD - Misc","p_event":"LD31","p_time":"1420930260","p_likes":"5","p_comments":"0","p_status":"WAYBACK","us_key":null,"us_name":null,"us_username":null,"event_start":"1417737600","event_key":"26","event_name":"LD31"},"source_url":"2015\/01\/10\/sharpening-my-tools\/","text":"<p><strong>NOTE: So this\u00a0right here turned out to be way more than I thought I\u2019d be writing, sorry for it not being a 100% Ludum Dare topic. I will be using this language and my game library for future Ludum Dare events, though, so it applies well enough I guess.<\/strong><\/p>\n<p>This past Ludum Dare I\u00a0got to use some very fun tools to create my game: A game library I wrote, Artifakt, with bindings to a scripting language that I also wrote, Score. Actually building something\u00a0like a game using tools I\u2019ve created, especially a whole language, is something I never thought I\u2019d be doing. The event was fun, but not without struggle,\u00a0so I\u2019m glad I already had upgrades planned for the future.<\/p>\n<p>I\u2019ve been working most on the language, rewritten completely from scratch it\u2019s a lot more efficient when it comes to\u00a0maintaining proper control of the program and has more flexibility\u00a0when it comes to the more complicated features I\u2019ve wanted. While the new Score lacks it\u2019s own proper class system like the old one had, the current functionality is actually far greater.\u00a0Functions, for example, are much more useful and manageable than before.<\/p>\n<p>Here\u2019s a quick example of some of the fun things\u00a0Score can do, because why not.<\/p>\n<p><a href=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2015\/01\/score_screenshot_0.png\"><img alt=\"score_screenshot_0\" class=\"alignnone size-medium wp-image-431712\" height=\"107\" src=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2015\/01\/score_screenshot_0-300x107.png\" width=\"300\"\/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>This might be a little confusing at first glance, so I\u2019ll go ahead and walk through it.<\/p>\n<ul>\n<li>Lines 1 and 2 import classes from Java for this script to use.<\/li>\n<li>Line 4 starts defining a table value. A table in Score is similar to a table in Lua, it stores data in key\/value pairs. By default a table doesn\u2019t care about the type of an object.<\/li>\n<li>Line 5\u00a0sets\u00a0the key\u00a0<code>in<\/code> to a new Java Scanner object in the table.<\/li>\n<li>Line 6 sets the key <code>Input<\/code> to a lambda function, more on that in a second.<\/li>\n<li>Line 12 defines two values as the\u00a0return values of the Input function.<\/li>\n<li>Line 13 prints stuff. The string concatenation is pretty standard, and the comma separation concatenates the values with a space between them.<\/li>\n<\/ul>\n<p>So more on that lambda, there. For reference that could just as easily be written as a standard function, putting <code>Input<\/code> right before the parameter list. Anyway, there\u2019s a lot going on there.<\/p>\n<p>First of it\u2019s defined with the keyword \u201cfunc\u201d and\u00a0followed by a list of variables in brackets. This first list is optional and defines specific return values for this function. If no return list is given any number of any type of object may be returned. If a list is given with no names for the values then only values of those types can be returned. here we have types and names, so the state of those variables is what gets returned whenever the function terminates. In this case the function terminates at the end with no early break. These return types, if given names, can have default values. Those work how you\u2019d think they do, they\u2019re initialized to that value rather than null or a type-specific default value (i.e.zero for an int.)<\/p>\n<p>After the return type list comes the parameters, which functions just about how any other parameter list would. You define values separated by commas and have the option of giving them defaults. What\u2019s good to note is that Score will automatically default parameter values if no argument is passed for them, so default assignments have no restrictions on where they can be used.<\/p>\n<p>After the parameters we have the function body. A neat thing that Score allows is that for single line functions the curly braces are optional: <code>func PrintValue(var value) println value;<\/code> is valid syntax. Functions can also use a fat-arrow to bypass the <code>return<\/code> statement: <code>func Add(int a, int b) =&gt; a + b;<\/code> will return the sum of a and b. Moving on from things not in the example, this function will first print the given message (or \u201cInput: \u201d if no message is specified) and then request input through Java\u2019s Scanner class and assign that input to the <code>res<\/code> return value. When the function returns after that, the value of <code>res<\/code> and <code>code<\/code> are returned.<\/p>\n<p>Notice how <code>in<\/code> is a part of the table but <code>Input<\/code> can access it without having to reference the same table. In Score, when a function is assigned to an object (or a part of a class, but we don\u2019t have classes yet\u2026) that function has access to it\u2019s container through a <code>this<\/code> parameter. Access to <code>this<\/code> is also delegated automatically as if its contents were local variables. Because of this the <code>Input<\/code> function has direct access to <code>in.<br\/>\n<\/code><\/p>","time":"January 10th, 2015 10:51 pm","title":"Sharpening My Tools\u2026","title_was_empty":false}