# Negative variable values in Inform 7

Just want to make sure I am not missing out on something simple here.

Test code:

``````Lab is a room.

To decide which number is negative of (n - a number):
Decide on -n.
[Decide on 0 - n.]

Fooing is an action applying to nothing.
Understand "foo" as fooing.
Report fooing:
say "Negative of 30 = [negative of 30]".
``````

The result is the compilation fails.

If I use the commented line instead, where I subtract the variable from zero, it works.

In Inform 7, is subtracting the variable value from zero the only way to get the negative of the value of a variable or is there some other way I don’t know about?

Putting parentheses around the longer version works for me:

``````To decide which number is negative of (n - a number):
Decide on (0 - n).
``````

Yes, as far as I know I7 doesn’t have a unary minus operator. (It might have one within equations, but the documentation doesn’t say and I don’t have a compiler with me to check.)

Note that it does have negative literals (-10, -6.28, -5 degrees Celsius, etc), and supports subtracting from zero and multiplying by negative one.

4 Likes

Okay, that’s what I figured. My original problem was using an equation – I just made the test code as simple as I could make it – so I can confirm that the unary minus operator does not work in equations either. Just wanted to make sure it wasn’t a piece of Inform 7 syntax I didn’t know about. Thanks for the confirmation.

1 Like

You could define this phrase:

``````To decide which number is - (num - number):
decide on 0 - num.
``````

But you’d have to add a space:

``````To decide which number is negative of (n - a number):
Decide on - n.
``````
2 Likes

Hah! That’s awesome. Yes, that is about as close to a unary operator as you can get.