Negative values

NOTE: I HATE A LOT OF YOUR ZZT GAMES, SO WATCH OUT!

Moderators: Commodore, Zenith Nadir

Post Reply
User avatar
Quantum P.
Level 17 Accordion Thief
Posts: 1433
Joined: Fri Sep 12, 2003 1:41 am
Location: Edmonds, WA
Contact:

Negative values

Post by Quantum P. »

I don't know if this has been discovered before, but I'll post it anyway.

I've been fooling around with the ZZT file format for about the last week or so. There are two numeric types used - unsigned 8-bit integers and signed 16-bit integers (little endian). Basically, that means that the numbers ZZT uses either fall in the range of 0 to 255, or -32,768 to 32767.

I find this interesting, because a lot of the numbers in ZZT don't make sense if they're negative. There are such things as 16-bit unsigned integers (range of 0 to 65535), but for some reason, the only 16-bit integers ZZT uses are signed.

So, I started wondering what would happen if you inserted negative values where they didn't belong. As it turns out, you get some pretty interesting stuff!

Unfortunately, none of it is really useful. Items and cheats can modify negative counters, but #give and #take can't. Some counters don't do anything interesting (I was kind of hoping negative health would make some kind of unkillable zombie, but it just ends the game). There are a couple of internal counters that indicate how much of a lit torch or activated energizer is left. Negative values for these don't do anything useful. You can set them to 32,767 to start off the game with a lit torch and an activated energizer that remain for a really long time (almost an hour if I'm calculating right), but once it burns out, it's out, and all other energizers/torches should last for the default duration.

If you set ammo to -1, you can still shoot, and your ammo count keeps on going down (-2, -3, etc...). After 32,767 shots, the counter is at -32,768. This is the lowest possible number - another shot will cause it to wrap around to 32,767, the highest possible number (think odometers here). This means you get a total of 65,535 shots before your ammo count reaches zero. This does not work for torches, though.

However, this doesn't really matter for practical game making. To get near-infinite ammo and torches, a #give ammo 10000 and a #give torches 10000 at the beginning of the game is good enough for almost all purposes, and in my opinion, it's more elegant to avoid negative numbers. Negative values in ZZT are really more of a curiosity than anything else.
gingermuffins
Posts: 371
Joined: Fri Sep 01, 2006 1:30 am

Post by gingermuffins »

weird stuff. The thing about the hour-long energizer's given me an idea.

Just wondering, did anything happen with score? maybe a negative value won't register on the hi-score sheet, and you wouldn't have to look at it every time you get an endgame.
User avatar
Quantum P.
Level 17 Accordion Thief
Posts: 1433
Joined: Fri Sep 12, 2003 1:41 am
Location: Edmonds, WA
Contact:

Post by Quantum P. »

Negative values don't get you on the high score table - but neither does a score of 0, so it's not unique to negative values.

Personally, I'd have an object that #takes all remaining score after ending the game. That way, you'd be able to use the score counter for engines and stuff.
User avatar
Surlent
Oh man not him again
Posts: 129
Joined: Fri Jan 12, 2007 5:16 pm
Location: Western US

Post by Surlent »

I knew I should have posted. =( I started playing around with negative values after gingermuffins went on his discovery spree, but then got busy
with other things and haven't had time to continue. I can't believe someone
else would try the same thing. Oh well, congratulations, this is some neat stuff.
JESUS CHRIST- You start the New Testament
with this Jesus. He is so superpowered and awesome, you feel converted. You place your hope in this Jesus.
Post Reply