User Tools

Site Tools


places:memtutvi

Memories VI - Levers, Switches, Dials

Levers, switches, and dials. Aren't they fun? Don't they just take up the memories at one each? Wouldn't it be good if you could fit several into one memory? Well you can. There's a trick that was mentioned in memories II where you use different digits in your number to stand for different things.

Suppose for example you have a lever which can be up or down, a switch that can be on or off, and a dial that can point to any one of four settings (the library, the belfry, the kitchen, the garden, say), oh and you'd like to use that gadget to count how many times somebody's been visiting and open up new areas for frequent guests, (see here).

The trick is to use one digit of your memory, the first say, to count how many times somebody's been in your room, then subsequent digits to code your levers, etc. So you can code the lever as 0 = Down; 10 = Up, the switch as 0 = Off; 100 = On, and the dial as 0 = Library; 1000 = Belfry; 2000 = Kitchen; and 3000 = Garden. So if the number stored in your memory is 2015 then this tells you that the dial is pointing to 'Kitchen', the switch is off, the lever is up, and your guest has been in the special room five times. If the number is 3107 then the room has been visited seven times, the lever is down, the switch is on and the dial is pointing to 'Garden'.

Well that's all very well and good, but how do you read this? It's easy enough as a human being to just glance at the number and see what's going on, but you want to be able to read this with programs. Somewhere else you want to know whether the swithch is On or Off. The switch will be On if the number is 112, 3108, or many other combinations. How do you deal with this?

You use the Memory Part Contrivances (Memory Part Equal, Memory Part Greater, and Memory Part Lesser). When you use these, you will find that their parameters include not only which memory to look at and what number to compare it to, but also which digit you want to look at. So in the above example if you want a program that shows a door whenever the switch is on, then your program should have on the first line a Memory Part Equal Contrivance with parameters set to the correct memory, memory digit three (hundreds) and check for one. Underneath this have an Unlock Door Contraption.

Note: In order to increment memory parts, use the normal Increment Memory Contraption. To increment the second digit, the tens, by two say, then simply add twenty to the whole memory.

There is a potential pitfall to be aware of here. In the above example, where the first digit is being used to count how often a player has entered a particular room, consider what happens if they have already visited that room nine times, and then visit again. The digit doesn't change to ten, since ten isn't a single digit. What happens is that the first digit becomes zero and the the second digit increases by one. Pushing the lever up if it was down, and changing it to some sort of undefined state if it was already up, which could have strange and unpredictable consequences depending on how you have programmed things elsewhere. This has a technical name, it's called an overflow error as the changes made to the first digit “overflow” to the second.

For this reason when using separate digits to stand for separate things, it is important to check that your digits aren't incremented past nine. When digits are being used to code for specific situations as in the lever, the switch and the dial above, then this usually happens automatically. If you are using the digit to count entries into a room or something similar, then slipping in a Memory Part Greater/Lesser Contrivance first to check that the digit is low enough before trying to increment is a good idea. Which one you use will depend on circumstances. If for example you just want to show a page if your memory part is nine, but show a (different) page and also increment the decimal part by one if the memory part is less than nine, then it makes sense to want to put the “memory part equals nine” Show Page in the escape hatch, and the “memory part less than nine” part of your program on the line underneath, which has more room. Or depending on what Contrivances you have in stock, use a “Memory Part Greater” Contrivance and fiddle with the flow control knob.

Memory parts are less flexible than whole memories, as there is no Set Memory Part Contraption, which can be a drawback in some situations. In the above example with the dial, if you wish to handle changing the dial by having a page for each setting, clicking on the link to a given page changes the dial to the appropriate setting, then this could be quite hard. Then you would have to have a program that checks to see what the current status is and add the appropriate amount with an Increment Memory Contraption.

Now you can fit lots more fun things into your memory. In the next memories tutorial we will look at another way of using one memory to remember several different things.


Proceed to the next memories tutorial.
Return to the previous memories tutorial.
Return to Places overview.

places/memtutvi.txt · Last modified: 2023/11/21 18:04 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki