Tiny Text Worlds


To help get me get up to speed on Haxe, and in particular Haxe JS stuff I have been working on and off on a prototype of text adventure engine. The three main things I wanted to achieve were:

  • I wanted to make a game my mum could, and would want to play. So I simplified the input so that the player should be able to see clearly which objects can be interacted with.
  • The game should have a constant scene description of the that changes as you alter or learn about the objects in it. In the game any object who’s text has changed text is highlighted red.
  • That it should work well on any device with a browser. I was particularly trying to make a decent experience on mobile. It seems to work OK on the browsers I’ve tested, touch areas on a Kobo eReader seemed a bit small.

I’d be really interested in some feedback on how people think the prototype works.

You can play it here:

The Xml the world is loaded from is here:

And the source is here ( MIT )

Should you feel the urge to use it please feel free do so, with the exception of the demo world.


Tracing to the “haxe:trace” div in Haxe 2.10 & 3.01 JS

Up until Haxe 2.10 using trace in the JS target wrote the contents of your trace to the <div> in the html file with the id “haxe:trace” something like this:

Main.hx:34: The contents of the trace

That’s changed with 2.10 with the content of the traces often being written to the browsers console (ctrl+shift+K in Windows or option+apple+K on a Mac).

Some kind folks on the mailing list gave me some pointers on how to switch back to writing to the <div id=”haxe:trace”> by setting the trace function to a method you’ve written yourself.

To change the trace method used by haxe you need to use ( and change divTrace to the name of your new trace method):

haxe.Log.trace = divTrace;

Here’s my method which traces out all the info in the PosInfos object which you can read a bit about here:

Haxe 2.10

public function divTrace(v:Dynamic, ?i :PosInfos)
	Lib.document.getElementById("haxe:trace").innerHTML +="<br>[" + i.fileName + " : " + i.lineNumber +"] " + i.className + "." + i.methodName + "() - " + v;

Haxe 3.01

public function divTrace(v:Dynamic, ?i :PosInfos)
	Browser.document.getElementById("haxe:trace").innerHTML +="<br>[" + i.fileName + " : " + i.lineNumber +"] " + i.className + "." + i.methodName + "() - " + v;

It writes something like this to the <div id=”haxe:trace”> in the html:
[Main.hx : 34] Main.new() - The contents of the trace