Tuesday, May 31, 2011

TRPG Progress

Without getting into too much detail:

I've converted my existing code to work with XNA 4.0. This was a bit of a pain here and there, but I finally fixed that issue.

I am still having a strange issue where I cant currently add new sounds to my content because of a reoccurring crash when I go to open the sound importing software XNA comes bundled with. I'll eventually need to figure out how to fix this although most of the solutions I've read about sound like a pain in the ass.

I've dropped my old Map code and file structure and brought it Jim Perry's version from his XNA RPG book. In the next few months I'm going to start tweaking it to be more in line with the movement style of a TRPG. I might need to do a lot of work on Entities (characters) in conjunction with this, not sure yet.

The content Toolkit is coming along in line with the engine, but I'm not planing on working on it much for a while until my engine is closer to baseline.

Side note:
Sorry for the long silence. My focus has been primarily on reading and exercise lately, but I'm starting to start bringing back development as a priority. Not enough hours in the day to stay well rounded without dropping some hobbies. Gaming, bass, and hockey have all taken a big hit while exercise and reading have come to the front over the past year.

Monday, February 07, 2011

Javascript:101, Week 2, Homework

Homework:


1) Exercises 3.1 from chapter 3 of Eloquent Javascript
My answer is at: http://jsfiddle.net/Gorlith/qAVyF/

2) Exercises 3.2 from chapter 3 of Eloquent Javascript
My answer is at: http://jsfiddle.net/Gorlith/Kyekg/

3)
a) http://jsfiddle.net/Gorlith/zxqkj/
b) http://jsfiddle.net/Gorlith/WPA6s/
c) http://jsfiddle.net/Gorlith/ueY4T/2/

JavaScript:101, Week 2, Reflections

Questions for reflection:
  1. Why do languages provide the switch statement, when we can achieve the same thing with multiple if... elseif statements? Show one example of how you might use the switch statement.

    Reasons to use switch statements include: better readability, easier to debug/maintain, faster execution is the compiler has that capability.

  2. What is encapsulation, and what do functions encapsulate?

    Encapsulation basically means that things inside of a function are separate from those things outside of it.
    It should be noted though that is JavaScript you can access variables that are outside the function (1 step above). So for example I can have a string that says "foo" in the main JavaScript area and then inside of a function say that this variable is now "bar". The version outside of the function is not changed.

  3. What is a pure function? Is the function show() provided in Eloquent Javascript a pure function?

    A pure function doesn't affect anything outside of its self. Meaning a pure function doesn't change the value of any global variable or anything like that.

  4. What do we mean when we say a variable in a function is shadowing a top level variable?

    When a variable is referenced in a function it looks for it inside the function first, then outside the function. This means you can have a value inside the function with the same name as one outside the function and know that the one inside will be the one used.
  5. A recursive function, must have some sort of an end condition. Why would we get a "out of stack space" error message if a recursive function does not have an end condition?

    If there is no end condition the function will just keep getting called 'infinity' until there isn't enough memory to have more instances of it on the stack.
  6. Reflect about the difference between object inheritance and class inheritance.

    Object inheritance allows you to basically make a copy of an object that you expand upon. Class inheritance means that you need to define a new class tat extends a previous class and then create objects of that class.
  7. What is object augmentation, and how do we do it?

    In JS you can add members to any object at any time by assignment. This can be very useful if you need to add a new property or function to something.
  8. There is a way to add a method to String, such as any new String we create will have that augmented method (this is a bit different from object augmentation). How would you do this?

    You can add a method to array.prototype and it will be added to all arrays. Strings are an array of letters.
  9. What is garbage collection?

    Garbage collection means that the js environment clears the memory for items that are no longer referenced in the program. Meaning that you aren't wasting system memory on objects that  you've already deleted or that were created inside of a function call.
  10. What is the difference between an array and an object?

    An array links to array.prototype and therefore has array functions. It also has a .length that is meaningful. An object links to object.prototype and therefore has object functions. Use arrays when you need to access things according to order, use objects when you want to access things by assigned names.

Tuesday, February 01, 2011

Javascript:101, Week 1, Assignment

Homework:

Exercises 2.1 - 2.6 from chapter 2 of Eloquent Javascript


2.1)
Yes, this evaluates to true. it eventually reduces down to true && ! false which reduces to true.

2.2)
var result = 1; 
var counter = 0; 
while (counter < 10) { 
result = result * 2; 
counter = counter + 1; 
} 
show(result);

2.3)
var result = "";
var counter = 0;
while (counter < 10) {
  result = result + "#"; 
  print(result); 
  counter = counter + 1; 
}

2.4)
var result = 1
 for (var counter = 0; counter < 10 ; counter = counter + 1)
 result = result * 2; show(result); 

var result = "";
for (var counter = 0; counter < 10 ; counter = counter + 1) { 
  result = result + "#";   print(result); 
}


2.5)
var answer = prompt("What is 2 + 2?", ""); 
if (answer == "4")      
  alert("yay!");
else if (answer == "3" || answer == "5")      
  alert("Almost!");
else      
  alert("You idiot!");

2.6)
var answer; 
var flag = true; 

while (flag) { 
  answer = prompt("What is 2 + 2?", ""); 
  if (answer == "4") { 
    alert("yay!"); 
    flag = false; 
  } 
  else if (answer == "3" || answer == "5") { 
    alert("Almost!"); 
  } 
  else { 
    alert("You idiot!"); 
  } 
}

Create an example that shows a valid use of the 'guard' and 'default' operators in Javascript.

The 'guard' operator allows you to elegantly defend your code from executing an undefined function.
For example say you want to get a users first name if the user object is properly populated. You could write this as:

var firstName =  user && user.getFirstName();

The function wont be run if user doesn't exists, keeping your code from failing.

The 'default' operator lets you return a default value if the requested value isn't defined. An example would be returning some default value when filling in data or showing data.

var quantity = prompt("Quantity") || 1;

Monday, January 31, 2011

Javascript:101, Week 1, Reflections

After a really hectic end to last week it's finally time for me to start working on my two P2PU courses.

This post addresses the questions to reflect on for week 1.

Questions for reflection:
  1. The alliance of Netscape and Sun Microsystems did not use Java in the browser, because it was not suitable for that purpose. Why do you think Java was not suitable to be embedded in a browser?

    Java was far too robust. If they embedded Java in a browser it would have been too bulky and the websites would have been very difficult to make and very clumsy and slow. Would probably not have been fully 'load and go'
  2. When parsing a String into a number using the parseInt() method, we are advised to always provide the radix. Why is it so strongly recommended?

    Giving parseInt() a radix argument tells the function in which base to parse the number. If you don't specify this it could interpret the number incorrectly. For example, when parsing '08' it may see the leading zero and decide that it is in octal. It will then see the 8 and terminate, giving you the result '0'.
  3. What is a type, and why do you think types are useful in writing programs?

    The type of an object lets the compiler know how much space the object might take up. Boolean values, for example, can only have 2 possible values, while numbers can have 2^64 values. If a language had no types then the compiler would most likely be made to assume that all objects needed the maximum amount of space needed for all types, meaning that it would set aside the same space for a binary value like a bool as it would for a more complex object like an array or hash table of strings. This would be very inefficient, and probably easy to exploit as well.
  4. Why do we lose precision when performing operations with decimal numbers in Javascript? Can you think of a few implications of why this would be a problem?

    JS doesnt handle arithmetic well with decimals. The common example is 0.1 + 0.2 doesn't come out to 0.3. It returns something like 0.30000000000000004. So the way around this is to take numbers and multiply them by 100 or whatever so they become whole numbers, do the math, then divide by 100 and display the results to the appropriate precision. This is a work around but with both you can end up with discrepancies over time. This can be dangerous when dealing with money.
  5. Do you understand why the following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500

    Order of operations. First (), then * /, then +-. So the above works as:
    115 * 4 - 4 + 88 / 2
    460 - 4 + 44
    500
  6. What does typeof 4.5 do, and why does typeof (typeof 4.5) return "string" ?

    The typeof() function returns a string telling you the type of the given value. (note: there are some errors.) The string "number" is returned for typeof(4.5) and typeof(typeof(4.5)) returns string because the inner call to typeof returns a string value.

Friday, January 14, 2011

School of Webcraft: jQuery ~ For the Love of Dollar

The other School of Webcraft course I signed up for (and got accepted into, awesome) is jQuery ~ For the Love of Dollar. It's an intermediate level course on using jQuery and sounds awesome.

We had to do a sign up task as well. It basically involved using http://jsFiddle.net/ and http://jsconsole.com/ to play around and learn a few simple tasks like changing fonts and counting objects.

The course is going to be using an open source ebook: http://jqfundamentals.com/book/book.html

Looking forward to class starting in ~2 weeks!

Thursday, January 13, 2011

School of Webcraft: Javascript:101

The signup for P2PU and Mozilla's School of Webcraft has finally arrived and I am signing up for a Javascript:101 course. As a task to see who is ready to join the course we had to watch a video and complete a small assignment.

The video gave a history of Java, Javascript, and the process through which it became standardized. It seems that many companies played a part in the standardization and that because of this certain quirks and errors that are known problems still remain.

Some notes I took from this:

  • JavaScript is loosely typed
  • objects are dynamic, they are basically hash tables
  • Prototypal inheritance: objects inherit directly from other objects, not classes
  • Lambda functions are treated as 'first class' objects
  • Linkage through global variables. This can cause many problems and is often a security risk. Need to learn to mitigate this problem.
  • values:
    • number
    • string
    • boolean
    • object
    • null
    • undefined
  • NaN is the result of undefined or broken operations
    • NaN doesn't equal anything, not even NaN
    • It's type is number.
  • Javascript has a ton of unused reserved words.
  • != and == can cause type coercion, use !== and === instead as they give exact equality.
  • && and || are a bit different in js
  • Bitwise operators are slow in js.



I also had to produce a bit of javascript that pops up an alert showing the results of 2 + 2.

The code is as follows:

<html>
<head>
<script type="text/javascript">
function message()
{
var x;
x = 2+2;
alert(x);
}
</script>
</head>

<body onload="message()">

</body>
</html>

It produced the following results:

Thursday, December 09, 2010

Chrome Web Store is open

Lot's of cool web apps to play with, many of them are optimized for chrome. I'll make a list of some of my favorites late on.

Tuesday, November 09, 2010

This isn't Jersey!

Reading:
Book 13 of WoT came out on November 2nd. It was really damn good. Since book 14 is going to the finale BS was able to focus on finishing long running story arcs. This book was EPIC.

About 80% through Theodore Rex. Colonel Roosevelt comes out this month, but I'm not going to get it until it comes out in paperback.

Brewing:
Tomorrow I'm going to check out a local homebrewes club. I'm excited. Then on Thursday me and Andy Tasso are brewing up 2 batches of beer. Awesome.

Game Development:
I spent last weekend uninstalling most of my development tools and and I installed the nice little bundle that Microsoft's new 'AppHub' offers. I'll play around with this soon.


Other:
Tanya and I are living in MD now, yikes.
AMC premiered 'The Walking Dead'. It's awesome, watch it.
Now that I'm in a 1st floor apartment I can work out my kettle-bells like a fiend.