Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Wednesday, November 11, 2009

Lost in a Sea of Ideas

The following is a repost as the original got spammed with junk comments and Blogger dosn't have an easy way to remove large numbers of comments in one hit without dropping the entire post.


I have found myself lost in a sea of new concepts lately. Firstly I read Andrew Poltkin's presentation on Rule based systems in Interactive Fiction. I have to say it was discouraging in terms of the RPG I was writing. Short point being that This is harder then you think it is.

Then I came across the following article (PDF). Which is an interesting read. And raises a point that I missed the last time I saw it. Namely stop treating JavaScript as it it was a class based language with awkward syntax.

The thing is that It is a prototype based language with two kinds of links, and a couple of missing functions. The big problem with learning to write JavaScript properly is that most tutorials make this mistake, And their is a lot of truly awful JavaScript code samples out their.

I don't really have any new insights on prototype based inheritance (yet), so if your interested have a look at Douglas Crockford's JavaScript site. I won't pretend that I get everything Douglas is getting at but I'm convinced that he understands it and that this is a good place to start hacking.

So where does this leave my project?

Up in the air a little. As I'm determined to do it right as it where. And need to teach myself how to operate effectively in a prototype based language. I'm pretty well sold that a rule based approach might be the best thing I can do. I encountered this when I tried to add conditional logic to my RPG, My conditional tests required inimate knowledge of how the engine stores its data, which seemed way to coupled. What I seemed to need was a simpler data organisation. I can't think of anything simpler then a flat database of facts, and that sounds pretty rule based. So Murphy's law is in full swing and I'm going back to the drawing board. Just as soon as I've learnt some new tricks

Thursday, April 23, 2009

An RPG in JavaScript

I've spent my train time for the last two weeks working on an wrting an JavaScript RPG (Thats Role Playing Game) system. The end result is intended to be a cross between the system used by Kingdom of Loathing and a traditional text adventure.

So far I've been boged down with a lot of low level mechanics, and ensuring that all my objects can round trip between JavaScript and XML. E4X makes this far less painful then it would otherwise be. The plan is to have a JavaScript game engine that executes XML based adventure files. Why XML? because JavaScript can allready parse it and it will be less cryptic then JSON. I'm musing that an adventure creator would also be nice, and would give me an excuse to play with XUL.

E4X means that at the moment my engine will only run in Firefox. But then this is a hobby project and I have better things to do then deal with the Pandora's Box of cross browser issues. Especially as Firefox 3 already implements so many goodies from HTML5 and ECMAScript 5th Edition.

Though I can't wait for the next beta of Firefox 3.5 and the @font-face CSS property. That and border images Should really come in handy when I get around to putting an interface page together.

Monday, March 09, 2009

JSEXT

I've been playing with a javascript library, which works as both a command line, and server-side execution Environment. Its called JSEXT and is a rather interesting beast. plus you can call your server side functions from script that executes in the browser, and JSEXT will generate the boilerplate needed for the AJAX call automatically.

For one thing it provides an incredible amount of auto loading magic, which sees it find not only functions in other javascript files but also in C header files. Any C library will effectively be usable form javascript. That got me thinking Cairo is a C library

Getting the helloworld example from the Cairo FAQ going was reletivly simple. But JSEXT provides something better, an OO wrapper for the Cairo library. Granted I did have to check the source out from SVN and compile it to get them, and then sort out a couple of minor bugs in the wrapper.

Anyway the following code is a slight modification of the basic example. This script is intended to be accessed from a web browser as title.jsx?"Insert your text here" and yes it works perfectly fine if you set the src attribute of an img tag.




function(str){
this.responseHeaders.contentType = "image/png";

var surf = new JSEXT1.Cairo.Surface.image("ARGB32", 800, 80);
var cr = surf.context();

with(cr){
selectFontFace("serif", "normal", "bold");
fontSize = 32;
source = [0, 0, 1];
moveTo(10, 50);
showText(str);
}
surf.writeToPNG(stdout);

}


Yes this is a file containing one anonymous function. This is one of the more curious features of JSEXT. You can give it a directory tree and it will walk it and build a set of Javascript objects based on what it finds. This does requie one method per file, which is somewhat unusual. But seems to work alright in practice. It is also uses lazy loading so only the methods you actually use get loaded into the runtime.

Thursday, February 26, 2009

Javascript Solution

I've been doing two things recently. Messing with CORBA and adding a small JavaScript effect to a web page. Working with CORBA is technical and challenging, and you would think interesting. To tell the truth CORBA has a somewhat unjustified bad reputation round the office. It dosn't fit perfectly to python, that is true, but it is still a very fast and reasonably secure way to do RPC.

The little JavaScript solution was suprisingly more enjoyable. Now I don't do much fornt end work so I had to look up essentially everything, and had one approach not work, for no obvious reason that I could see. But on the whole it was more enjoyable. I suspect that the immediate visible feedback provided by making a change, reloading the page and seeing what would happen, had a lot to do with it.

I'm think I can see more web design work in my near future. And more javascript. wxJavascript or GLUEScript as it is to be know from the next version onwards is worth a look. Especially as I like the wxWidget toolkit. Don't know if I'll be sufficently motivated to build it myself though.