Number in if phrases does not work as intended?

So I did something like this:
Every object has a number called val. The val is usually 1.
and:
the description of xxx is “[if val is 1] blahblah [otherwise] NO.”

but the result is always NO. I tried to directly print the value of val and the result is 1, but [if val is 1] returns false nonetheless.

I’ve since found a workaround like this:
the description of xxx is “[if val to the nearest whole number is 1] blahblah [otherwise] NO.”

But I still don’t understand why I have to phrase it like this? Any insight is greatly appreciated!

2 Likes

Yeah, that’s an odd corner.

You can avoid this by writing val of the item described instead of just val. But this isn’t always necessary, which is confusing.

The description of xxx is "Val is [val] -- [if val is 1]Its val is 1.[otherwise]NO."

In this description, the part before the dash comes out correctly; it understands that [val] means the val of the object. But in the if statement, it doesn’t.

You can write

The description of xxx is "Val is [val] -- [if val of the item described is 1]Its val is 1.[otherwise]NO."

…and get the correct result.

2 Likes

What causes this issue ambiguity? Could val refer to more than one thing, which is why you have to specify that it’s referring to the object described?

If you don’t specify of the item described, which val is being evaluated?

Thank you very much! Using val of the item described worked well.

But I don’t think my code is wrong in that the parser does not understand which val I’m referring to. I tested it by first print the desc of an object, then change the val of said object and print again, the result of both your solution and my makeshift solution are correct.

It doesn’t evaluate any object’s val. It’s computing val as an abstract property identifier, which is an I6 constant. This shouldn’t be compared with 1 – that’s a type error – but the compiler doesn’t notice.

2 Likes

Gotcha. So this is a bug in I7’s compilation step to I6 code, and something we can’t really workaround right now. Understood.

Also I’m not actually using val as a variable name. I named it something else.

Your example using [if val to the nearest whole number is 1] works correctly, yes. When you use val in an expression that way, the compiler goes back to the correct interpretation. You could also write [if val + 0 is 1] or any other expression.

1 Like

I see. Thanks a lot!