Archive for category TorqueScript

2D Game Building for Teens – Errata #4

There are not too many things wrong in chapter 8 of 2D Game Building for Teens — but the things that are wrong will keep your game from working.

First, on page 218 the line of code that looks like this:

function BattyPlayer::createDeathray()

…should look like this:

function BattyPlayer::createDeathray(%this)

If you don’t pass in a reference to $BattyPlayer your deathray will never show up. That code is also shown again on page 222 at the top.

At the top of page 219, as part of the playerDeathray::fire function, the lines of code should be like this:

        %this.setWorldLimit(kill,"-50 -30 40 30");
	%this.setLinearVelocityX(%this.missileSpeed);
	%this.setPositionX(%this.player.getPositionX()+4);
	%this.setPositionY(%this.player.getPositionY()+7);
	%this.setImageMap(deathrayImageMap);
	%this.setSize("8 4");//approximately half size of original graphic
	%this.setCollisionActive(true,true);
	%this.setCollisionPhysics(false,false);
	%this.setCollisionCallback(true);

Some of those lines are the same as in the book, I just pasted the entire chunk here to make it easy for you to grab the whole block.

I did make a couple changes, however.

The book uses %this.setPosition(%this.player.getPosition()) which is fine if you want to set the deathray to the same position as Batty — but the raygun is supposed to be shooting, not the bat. So I used setPositionX and setPositionY so I could add an offset for each and make it look like the deathray was actually coming from the gun.

The other change is in the setSize line – the book said to set the values at 83 and 38, but for me that made a HUGE deathray, the size of half the screen. The values shown above fixed things.

Why that kind of change, after all, we’re only trying to set the size of a known graphic?

I’ll explain why in another post here later. =:)

That code above is also shown on page 222 as part of the entire listing.

One more thing, as in previous chapters, $BattyPlayer is mistakenly referred to as $MeBatty in the code on page 220 — make sure wherever you see $MeBatty you change it to $BattyPlayer.

2D Game Building for Teens – Errata #2

Here’s another big problem from the book 2D Game Building for Teens. Yes, the code examples are in rotten shape but the book as a whole is a good intro to Torque Game Builder — just make sure you keep checking back here for the fixes. =;)

On pages 163 and 169 the book shows the code for player.cs — and besides the problem shown in Errata #1 on this site, there is a huge chunk of the code shown that shouldn’t be there.

Basically, these functions…

BattyPlayerUp()
BattyPlayerDown()
BattyPlayerLeft()
BattyPlayerRight()

…are duplicated.

The first set shouldn’t be there — just rip those four functions right out and you should be good to go.

2D Game Building for Teens – Errata #1

The book, “2D Game Building for Teens” by Michael Duggan is the only book I’ve seen that covers Torque Game Builder — and since my son Tom is 15 I figured this book would be a great starting point for him.

Yes, and no. The book itself is very cool — but the code examples have some major problems.

My son spent hours getting to a point in the book where things just stopped working…

…the w, a, s, and d keys are supposed to move a flapping bat around on the screen.

Nada.

He spent hours trying to figure out what was wrong — he’s not a programmer (yet) so he had no idea what to look for. I finally found it after spending too long trying to find the typo in his code — turned out it’s a mistake in the book, he typed everything in correctly.

Hey, mistakes happen, right? So where’s the errata on the author or publisher site? It’s just freakin’ irresponsible not to have that available — especially for something that’s aimed at newbies.

So, for anybody else who comes across this problem, it’s caused by this line in player.cs:

$MeBatty = %this;

In that line you’re setting the global variable $MeBatty to the object that’s passed in to the function, but then other functions are referring to $BattyPlayer, not $MeBatty.

To fix player.cs (the full thing starts on the bottom of page 155 in 2D Game Building for Teens), just replace that $MeBatty line with this:

$BattyPlayer = %this;

Your bat should now fly around using the w, a, s, and d keys.