Lesson 5
Call me the Geomancer

It's time to take a little break. I don't think this topic is nearly as difficult as the last. The reason for this is that HamsterSpeak provides you with so many built-in constants.
If you haven't figured it out yet, this lesson focuses on four plotscripting commands:
  • writepassblock
  • writemapblock
  • readpassblock
  • readmapblock

  • These aren't as hard as they might look, although pass blocks use flag bits, which are technically a little like scan codes. Once again, the HamsterSpeak Dictionary helps us out here.
    Since it's the easiest, let's discuss the readmapblock command first. You use this command to find which tile is at a certain position.

     set variable(tilenum, read pass block(5,5))

    Okay, maybe this isn't as obvious as I thought. It's not too hard, though. Let's break it down.
  • Makes a variable called tilenum
  • Sets it to "readpassblock(5,5)"

  • Basically, the variable is set to the index of the tile at the position X=5, Y=5. Its sister command write pass block operates with the same index, so using both commands you could copy one maptile to another position. Useful? Maybe. You could make a really cheesy paint program that way.
    If you don't want to just copy maptiles, then it gets a little trickier. Go into the maptile editor in the OHRRPGCE. The upper left tile is tile 0, the tile to the right of that is tile 1, and so on.

    The other half of this lesson (and we'll come back to the first part later) is the passblock. It determines whether you can walk on the tile. Check out the predefined constants northwall, eastwall, southwall, westwall, vehicleA, vehicleB, harmtile, and overheadtile. They all deal with the passblock commands.
    To combine them, all you have to do is add them. In the following example from Sheep Rancher, a constant called "nopass" is defined as 15, which is the sum of northwall, eastwall, southwall, and westwall.

    define constant,begin
       if (keyispressed(key_s)) then
        if (herodirection(me)==west) then
        if (herodirection(me)==east) then
        if (herodirection(me)==up) then
        if (herodirection(me)==down) then

    When the player presses the S key, he uses the Crater spell. This makes a big hole that the player and the sheep can't get into or out of. It combines writemapblock, which makes the tile look like a big crater, with writepassblock, which makes the crater impassable.
    One of the trickiest parts of using the mapblock commands is figuring out what number a certain maptile is. An easy way to do this is to use showvalue with getmapblock. The number of the tile will appear in the lower left corner of the screen. You can then use that number in your scripts instead of using getmapblock every time. It will be much quicker with the actual number than with getmapblock.

    That's the end of this all-too-brief lesson. I'll try to get more stuff up quicker in the future. E-mail me your questions or sample scripts!

    Return to Main Menu
    Site layout (c)2000 Jennifer Raby. Used by permission.