Coding Task - 23 April 2012 - Make a Jetpack

Nope. Not a browser issue!

Curiouser and curiouser.

I’m at work now. It will be interesting to see if I can get it to work on my home computer (also running IE8). Maybe it just doesn’t like me.

Robert Rothman

More likely, Microsoft made IE really difficult to work with by not following standards.

Well, my machine at home has the same problem running this as the machine at work – which suggests that maybe somehow it is browser-related. I’m disappointed, because it looks like it could be fun to play around with, and I haven’t the foggiest idea how to go about getting it to work.

Robert Rothman

Hmm… I’ve got it working on IE9 so maybe there’s the snag, if you’re using 8 at home as well? I’m sure you can upgrade for free.

The reason is that for a web developer older versions of IE can be a total pain to work with and since the problem is easily solved on the user part with a free upgrade, most just don’t bother. For companies the extra development costs more money and for hobbyists it costs more of their time that could be better spent.

IE8 is fine if you just browse regular web sites but for web apps there will be more and more problems as the browser gets older and more sites drop support.

Very interesting - and reminds me, a lot, of those Lunar Lander games. In fact, this would have been a perfect entrant for that old “Arcade IF” comp

Attempting to make websites IE-compliant can triple the amount of time it takes me to make them, and it tends to involve egregious hacks. And the sites still look way less good in IE than any other browser.

This is definitely doable. I’ve been pottering away on something which is actually a glider and not a jetpack, and I, well, haven’t got around to implementing anything for the glider yet. Here’s the code for walking on the ground that I have so far – as you can tell I’ve just started on the sky.

[spoiler][code]“The Plains Glider” by Matt Weiner

Volume - Significant Rooms

A significant room is a kind of room. A significant room has a number called x-coordinate. A significant room has a number called y-coordinate. The x-coordinate of a significant room is usually -99. The y-coordinate of a significant room is usually -99. [-99 means off the map.]

Volume - Geography

Yourself has a number called x-coordinate. Yourself has a number called y-coordinate. Yourself has a number called z-coordinate.

To decide whether (locus - a significant room) is located at (x - a number) by (y - a number):
if the x-coordinate of the locus is x and the y-coordinate of the locus is y, decide yes;
decide no.

Table of Direction Increments
direction x-increment y-increment
north 0 1
northwest -1 1
west -1 0
southwest -1 -1
south 0 -1
southeast 1 -1
east 1 0
northeast 1 1

Volume - Towers

A tower is a kind of significant room. A tower has a number called height. The height of a tower is usually 50. The description of a tower is usually “[Item described] is [height] meters above the ground.”

Every turn when location is a tower:
now the x-coordinate of the player is the x-coordinate of the location;
now the y-coordinate of the player is the y-coordinate of the location;
now the z-coordinate of the player is the height of the location.

Instead of going down in a tower:
say “You descend the tower.”;
move the player to a random base surmounted by the location.

Instead of going in a tower (this is the can’t leave a tower rule):
say “You can only descend to the ground, or jump in the air.”

Locating the player on the surface is an activity.
For locating the player on the surface:
repeat with the new home running through bases:
if the new home is located at x-coordinate of the player by y-coordinate of the player:
move the player to the new home, without printing a room description;
rule succeeds;
repeat with the new home running through non-basic significant rooms:
if new home is located at x-coordinate of the player by y-coordinate of the player:
move the player to the new home, without printing a room description;
rule succeeds;
move the player to the Ground, without printing a room description.

To locate the player on the surface: carry out the locating the player on the surface activity.

The can’t go that way rule is not listed in the check going rulebook. The move player and vehicle rule is not listed in the carry out going rulebook. [If we have any rooms with normal navigation, we’ll want a special rule that reinstates these rules for them.]

Section - Bases

A base is a kind of significant room. Surmounting relates one tower to one base. The verb to surmount (he surmounts, they surmount, he surmounted, it is surmounted, he is surmounting) implies the surmounting relation. Every tower surmounts a base.

Definition: a significant room is non-basic if it is not a base.

The printed name of a base is usually “Base of [random tower surmounting the item described]”.
The description of a base is usually “[Random tower surmounting the item described] looms [height of random tower surmounting the item described] meters above.”

Check going a direction (called the way) in a base:
if the way is:
– down: say “You’re already at the bottom of [random tower surmounting the location].” instead;
– inside: say “[Random tower surmounting the location] is solid; you can only climb up the stairs spiraling around it.”;
– outside: say “You’re already outside [Random tower surmounting the location].”;
– otherwise: continue the action.

Instead of going up in a base:
say “You climb the tower.”;
move the player to a random tower surmounting the location.

Instead of exiting in a base:
say “You’re already outside [Random tower surmounting the location].”

Every turn when location is a base:
now the x-coordinate of the player is the x-coordinate of the location;
now the y-coordinate of the player is the y-coordinate of the location;
now the z-coordinate of the player is 0.

[The rule for leaving a base is subsumed in the rule for leaving a significant room; only the report rules are different.]

Volume - The Ground

The Ground is a room. “You are down on the flat plain, at coordinates <[x-coordinate of the player], [y-coordinate of the player]>.”

Instead of going up in The Ground: say “You’ll have to find a tower to climb.”
Instead of going down in The Ground: say “You’re already on the ground.”
Instead of going inside in the Ground: say “You’re in the open plain. There’s nothing to go inside.”
Instead of going outside in the Ground: say “You’re already outside.”
Instead of exiting in the Ground: say “You’re already outside.”

Report going when the location is the Ground and the room gone from is a base (this is the report going to the ground from a base rule): [This can’t be “going to the Ground” because the room gone to isn’t set to the Ground, thanks to our trickery with exits]
say “You trudge [noun] away from [random tower surmounting the room gone from].”

Report going when the location is the Ground and the room gone from is a non-basic significant room (this is the report going to the ground from a significant room rule):
say “You trudge [noun] away from [the room gone from].”

The report going to the ground from a base rule is listed before the describe room gone into rule in the report going rulebook.
The report going to the ground from a significant room rule is listed before the describe room gone into rule in the report going rulebook.

Carry out going a direction (called way) in the Ground:
if the way is not a direction listed in the Table of Direction Increments:
continue the action; [TODO: change this so it checks if there’s a real exit, and issues the usual message if there’s not]
otherwise:
choose a row with the direction of the way in the Table of Direction Increments;
now the x-coordinate of the player is the x-coordinate of the player plus the x-increment entry;
now the y-coordinate of the player is the y-coordinate of the player plus the y-increment entry;
locate the player on the surface;
rule succeeds [this seems to be necessary so this rule and the going in a significant room rule don’t run in the same turn; I don’t like it]…

Volume - Other Significant Rooms

Carry out going a direction (called way) in a significant room:
if the way is not a direction listed in the Table of Direction Increments:
continue the action; [TODO: change this so it checks if there’s a real exit, and issues the usual message if there’s not]
otherwise:
choose a row with the direction of the way in the Table of Direction Increments;
now the x-coordinate of the player is the x-coordinate of the player plus the x-increment entry;
now the y-coordinate of the player is the y-coordinate of the player plus the y-increment entry;
locate the player on the surface;
rule succeeds [this seems to be necessary so this rule and the going in the ground rule don’t run in the same turn; I don’t like it].

Volume - The Sky

The Sky is a room. “You are aloft in the sky at coordinates <[x-coordinate of the player], [y-coordinate of the player]>, [z-coordinate of the player] meters in the air.”

Every turn when the location is the sky and the z-coordinate of the player is less than 1:
now the z-coordinate of player is 0;
say “You glide to the ground.”;
locate the player on the surface.

Volume - Scenario

Icarus Tower is a tower. “Your home is the tallest tower on the plain.” The player is in Icarus tower. The height of Icarus tower is 100. The x-coordinate of Icarus Tower is 10. The y-coordinate of Icarus Tower is 5.

Tengu Tower is a tower. The x-coordinate of Tengu Tower is 5. The y-coordinate of Tengu Tower is 10.

When play begins:
repeat with floor running through bases:
now the x-coordinate of floor is the x-coordinate of a random tower surmounting floor;
now the y-coordinate of floor is the y-coordinate of a random tower surmounting floor.

Tiny Hut is a significant room. “A tiny, insignificant hut stands here. Don’t bother going in.” The x-coordinate of Tiny Hut is 7. The y-coordinate of Tiny Hut is 7. [The player is in Tiny Hut. The x-coordinate of the player is 7. The y-coordinate of the player is 7.]

Tinier Hut is a significant room. “A really tiny, insignificant hut stands here. It’s not implemented.” The x-coordinate of Tinier Hut is 8. The y-coordinate of Tinier Hut is 7.

[/code][/spoiler]

That is brilliant coding. However, there is something that caught my attention.

I see you are using “continue the action” and “rule succeeds” in carry out rules, but since carry out rules are “considered” rather than “abided by” in Inform 7, surely phrases like “continue/stop the action”, “rule fails/succeeds” and the like have no effect whatsoever, right?

I think the “continue the action” was a legacy of when I had the whole thing coded as an “instead” rule before I decided to break it up into check/carry out/report the way I’m supposed to. (And, as my comment in the code suggests, that whole thing is a mess currently – if you try going up or down in Tiny Hut it doesn’t do what it’s supposed to, because I’ve disabled the “can’t go that way” rule.)

“Rule succeeds” is necessary, though – if you comment it out and try “d/e/w” you’ll see that the last move skips you right over the base of the tower. What happens without it is that both carry out rules run in succession – when the first one fires the location is the ground, when the second one fires the location is the base – so you get moved two spaces in one turn. Per 18.10 the “rule succeeds” ends the carry out going rulebook (I think), so the second rule doesn’t fire. But it’s not ideal to end that rulebook, since there might be some other carry out rule that we want to happen, so I’ll probably ultimately take care of it by setting a flag to check whether we’ve already moved once this turn.

I believe that only applies the the before, instead, carry out and after rulebooks.

Also, I’ve tried using them in carry out rules to no avail before investigation showed that they were ignored.

I’m pretty sure that means that there’s no difference between “rule succeeds” and “rule fails” in the carry out rulebook, but “rule succeeds” is definitely making a difference – as I said, comment it out and “d/e/w” will yield different behavior.

Well, I’m not 100% sure what’s actually happening here, so I’ll check that out. Although, I do get the impression that I’ve overlooked something here.

I did some investigation and I believe I understand what’s going on here. While the carry out stage rule ignores the result passed through to it, the specific carry out rulebook doesn’t and it still ends.

I also managed to figure out why both rules were firing in the same turn. I believe that when the “locate the player on the surface” phrase in the going in the ground rule runs, it moves the player to a significant room and causing the going in a significant room rule to run. I also noticed that both rules are almost identical.

One solution is to replace this:

[spoiler][code]Carry out going a direction (called way) in the Ground:
if the way is not a direction listed in the Table of Direction Increments:
continue the action; [TODO: change this so it checks if there’s a real exit, and issues the usual message if there’s not]
otherwise:
choose a row with the direction of the way in the Table of Direction Increments;
now the x-coordinate of the player is the x-coordinate of the player plus the x-increment entry;
now the y-coordinate of the player is the y-coordinate of the player plus the y-increment entry;
locate the player on the surface;
rule succeeds [this seems to be necessary so this rule and the going in a significant room rule don’t run in the same turn; I don’t like it].

Carry out going a direction (called way) in a significant room:
if the way is not a direction listed in the Table of Direction Increments:
continue the action; [TODO: change this so it checks if there’s a real exit, and issues the usual message if there’s not]
otherwise:
choose a row with the direction of the way in the Table of Direction Increments;
now the x-coordinate of the player is the x-coordinate of the player plus the x-increment entry;
now the y-coordinate of the player is the y-coordinate of the player plus the y-increment entry;
locate the player on the surface;
rule succeeds [this seems to be necessary so this rule and the going in the ground rule don’t run in the same turn; I don’t like it].[/code][/spoiler]

With this:

Carry out going a direction (called way): if (the room gone from is the ground or the room gone from is a significant room) and the way is a direction listed in the Table of Direction Increments begin; choose a row with the direction of the way in the Table of Direction Increments; now the x-coordinate of the player is the x-coordinate of the player plus the x-increment entry; now the y-coordinate of the player is the y-coordinate of the player plus the y-increment entry; locate the player on the surface; end if.

Here, the rule will only fire once either way.

Hope this helps.

Well that makes a lot more sense. I think that they were originally split up into two different “Instead” rules because they print different things, but of course now that I’ve got that hived off into two different Report rules that’s not an issue. So I can just combine them into one carry out going rule. This will be useful because I may eventually want more carry out rules to keep track of how long it takes to haul your glider over different types of terrain, etc.

The real exceptions will be moving in towers (which is already blocked by the “can’t move away from a tower” rule) and if I want to have conventional motion in any places (for instance, if there’s a multi-room building anywhere on the plain). But I’ll need to write some special coding for that last case.

I guess this shows why it’s best practice to divide your actions into check/carry out/report rules from the beginning. Thanks!

The coding tasks seem to have gone dormant recently. Also, I believe it’s probably time for a new task. I have two more ideas for the next coding task.

  1. Implement a ferry crossing where the player can drive onto the ferry, but then has to exit the vehicle in order to sail the ferry.

  2. Create a game simulator, such as noughts and crosses, connect 4, poker, blackjack or maybe even nim.

I’ll leave the rest for you to decide.

I was thinking footprints would be an interesting exercise (people leave footprints behind them in rooms where they’ve been, which can be examined to see who’s been in that room).

Ooh that is interesting: especially if there are different animals or kinds of floor (mud, snow etc.)

Both good suggestions. Sorry for going AWOL but really glad this is becoming more of a community thing. Please everyone make suggestions! If something is too difficult / too easy then vary it to suit yourself. I look forward to looking at what people come up with, though I doubt I will have time to contribute until Uni crunch time is over (in a month or so). Good-luck!