Help for a beginner.

Hi there.

I have just started learning how to use TADS3. I am creating a game in it for my project in my final year of High School.

One of the conditions of the project is that it must include one of the following:

  1. File Handling (I was thinking of maybe a leaderboard being read into the game from an external source?)
  2. Sorting Algorithm (Like bubble sort or something.)
  3. A 2-d Array.

Thing is, I have no idea of the capabilities of TADS 3 for these types of things so, seeing as you all probably know a lot more than myself, I am looking for some advice on what could work, what wouldn’t, and how to implement a solution.

If anyone has the time to spare, your help will be greatly appreciated.


You asked about this on RAIF several months ago. Can you review the follow-up discussion and let us know what you’ve implemented and where you’re stuck?

Hi. Yes I remember this, but I thought since it had been inactive for a while I should start a new thread to continue it, if that makes sense?

Anyway, if I’m being completely honest, I have failed to make next to any headway with the file handling stuff at all. I think this is due to my lack of knowledge with TADS3. I just don’t know what to code and where to code it. :frowning:

I have, however, worked my way through the Getting Started guide (The Further Adventures of Heidi) so I guess I know the basics.

The more complicated stuff though just goes right over my head. The furthest I got was to write something like this:

local f = File.openTextFile(‘myfile.txt’, FileAccessWrite);
f.writeFile(‘Line of text\n’);
f.writeFile(‘Line of text\n’);

but when running got a nil object reference and thats where i got stuck i guess.

sorry for being so useless at all this :stuck_out_tongue:

Make sure you #include <file.h> at the top of the file.

Apart from that, what you posted should work.

modify WaitAction
	execAction() {
		local f = File.openTextFile('myfile.txt', FileAccessWrite); 
		f.writeFile('Line of text\n'); 
		f.writeFile('Line of text\n'); 

I tested it with ‘wait’ and myfile.txt was created with those two lines of text.

T3 lists and vectors (aka arrays) have a built-in sort function. You can assume that it’s efficient and there’s ordinarily no need to use anything else.

T3 allows you to extend these intrinsic classes with new methods and properties. These extensions run in VM code rather than native code, so performance will be strictly worse, but it’s still a straightforward matter to add your own custom sort.

Here’s a (pathological) example.

modify Vector
	randomsort() {
		/* are items in ascending order? */
		local sorted = new function() {
			local ix = 1;
			while (ix < length()) {
				if (self[ix] > self[++ix])
					return nil;
			return true;

		/* sort items with a random comparison function */
		local shuffle = new function() {
			sort(nil, {x,y: rand(-1,0,1)});

		/* seed the PRNG */

		/* the "algorithm" */
		while (!sorted()) {

modify WaitAction
	execAction() {
		local _vec1 = new Vector(9,[2,1,3,4,5,8,7,9,6]);
		local _vec2 = new Vector(9,[99,88,77,66,55,44,33,22,11]);


		_vec1.forEach({x: "<<x>> "}); "\n";
		_vec2.forEach({x: "<<x>> "}); "\n";

Hi there. Thanks for helping. Sorry for not replying before but with Christmas and New Year and everything i was quite busy.

I’ve tested what you suggested in games by themselves and they do work but that was never really in question haha. :slight_smile: However, and this is where your greater knowledge of the language comes in, I am wondering how I can manipulate this.

Ideally, what i want to happen is, at the end of the game, the player can take their score (or maybe number of turns taken) and enter it to a file with their name associated with it to form rankings. That’s when the sort would come in to rearrange the rankings so they were in descending order.

Is this sort of thing possible in T3?


Yes, you can write and read files. See the System Manual for more info.