I was searching around trying to find a 7-segment digital counter implemented in lua and was surprised that no one else seems to have made one yet. I'm not counting the Jason Harper one from Missed Island because that required a mess of platforms, an enforcer shooting various switches, and custom textures. Using lua is so much cleaner. Since I wasn't able to find one, I've implemented one myself.

I played around a bit with the map geometry to get something that looks decent. I found that the digits looked best the two vertical segments on the right side are taller and the two segments on the left side shorter. The end result is that the bottom segments of the digit 2 and digit 9 look a little off but overall is better than the other configurations that I tried.

Counter viewed from front

The numbering I designated for the 7 segments is 1 & 2 for the two segments that comprise a digit 1, then went clockwise around for the rest. Distances in W.U. are shown along the bottom. Here is what the digits look like when using the lava texture set:

Digits 0-9

To create the 7 segments in a map editor requires something like the 6 polygons shown in the image below. Floor/ceiling heights are shown for each polygon. I found that in Weland, using a custom grid scale of 0.2 with 1/8 world size works best so that the grid size is effectively 0.025 W.U. Once textures & lighting have been assigned, the polygons can be compressed down so that they are each only 1 internal unit tall in the Y direction, so that the digital counter doesn't protrude very far into the wall.

Map view

If you're still having trouble grasping what the finished counter looks like, the isometric view below should help.

Isometric view

The last step is to specify in the lua script the 4 lines that make up the sides of the 7 segment display. It is also possible to specify which textures and lights are to be used for the on and off state. See the script files for more details.

The 00_Counter.lua script creates a single digit counter 0-9. 01_DotCounter.lua creates a counter with 1 segment that can be used for displaying decimal points. 03_MegaCounter.lua is used to manage multiple counters and dot_counters to effectively have a multi-digit counter.

Finally, to demonstrate a multi-digit counter in action, I created a calculator with 7-digit display. Not that having a calculator in a marathon map is all that useful, but it does serve to test the limits of what can be implemented with a lua digital counter. I used custom textures for the buttons (not the prettiest but who cares?). The calculator buttons are not actually switches but are activated by the lua script when it detects the detonation of a projectile in their polygon.

Feel free to leverage the scripts in your own maps. Counter.lua, DotCounter.lua, and MegaCounter.lua shouldn't require any modifications to be used and are configured from the main script. I commented the code pretty extensively, but ask questions if anything is unclear.

This brings to mind a number of different things. There's Jason Harper's stuff as you mentioned - he was the first to show what computer engineering principles could do when applied to Marathon. It also reminds me of working on Excalibur: Morgana's Revenge. Though much simpler, we had a texture of red numerals on a black background, which I used to make a 'power readout' go from 100% to 0% when you flip a switch.*

But also, I remember a very old mod, possibly for Marathon 1, that claimed to spawn an alien for each running application on your system. The point was, you could force quit an app with extreme prejudice by blasting the corresponding alien in game. More recently, I'm reminded of what people have been doing with Redstone in Minecraft, making crazy things like functioning computers. What impractical fun, all of it.

* That gets me thinking. You're using custom texture(s) anyway, and each digit is much smaller than 1 WU. That being the case, you could draw an entire font worth of characters on a texture, and then use lua to offset each side's uv coordinates (.texture_x and .texture_y) to write arbitrary text on the walls. Just think, with some effort Marathon's terminals could be far more awkward to read.

Crater Creator wrote:* That gets me thinking. You're using custom texture(s) anyway, and each digit is much smaller than 1 WU. That being the case, you could draw an entire font worth of characters on a texture, and then use lua to offset each side's uv coordinates (.texture_x and .texture_y) to write arbitrary text on the walls. Just think, with some effort Marathon's terminals could be far more awkward to read.

Yeah, with custom textures there are tons of possibilities for what you can do. Still, arbitrary text written on the walls would really only work well for a handful of words. With each character requiring its own unique side, the polygon count would really rack up for a paragraph of text. My calculator demo uses 102 polygons, and it's just a small room!

Even though my calculator demo uses custom textures for the buttons, I deliberately wanted to implement a digital counter that works without needing to use custom textures. So if the counter script were used for a simpler application, like say a timer that shows time remaining for a level, there would be no need to use custom textures.

Hmm. You know, I just gave this some more thought. Originally I thought to myself this technique could be used not just for characters, but any image. You could progress through a sequence to make an animated flipbook. Then I remembered you can already do animated textures with MML, and so dismissed the thought.

But treating it as animating a texture's uv's, instead of flipping through frames, could still be useful. For some time now I've wondered about additional texture modes (texture modes are things like wobble, vertical slide, and landscape).

Using those .texture_x and .texture_y parameters, one could effectively create some novel texture modes. Though the possible effects are limited, with no way I can see to rotate or scale the uv's, any of these should be possible:

Make a floor texture scroll by in exact alignment with a liquid.

Make a wall that pulsates (map-based texture mode) and slides (lua-based texture mode) at the same time.

Make a column that fast wobbles when you hit a switch.

Combine one of these lua-based texture modes with, say, a new shader.

Slide a texture as the player's facing angle changes for a (maybe) pseudo-specular effect.

Theoretically, one can also do interesting texture effects with custom shaders in the Shader renderer. Unfortunately, you have to know GLSL (which isn't exactly easy to pick up) and one-off effects are hard because our API is currently minimal, mainly for lack of good use cases. If any GLSL programmers have a cool idea along these lines, PM me for more info.