• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

I'm confused about Not's precedence

Holzchopf

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
500
Code:
If Not 1=2 Then Print "SHOULDN'T THIS BE TRUE?"

won't print the text. Why? Because "Not 1" evaluates to 0 first, then "0=2" is evaluated, which is false.

Am I getting old or was this always like that in basic-like languages? I'm really confused :confused:
 
Maybe it is just parentheses. Not (1=2)
The question is what is "Not 1"

Should have read properly. Not 1 evaluates False
 
Last edited:
Yes, always use parenthesis around an expression which you want to negate.
 
I guess I only used Not in statements like If Not obj Or obj.state = STATE_DEAD Then where this doesn't strike since it's evaluating the boolean value of obj (e.g. null/not null). I couldn't explain why else I never knew about the precedence of Not. Of course in numerical comparisons I used to use <>, but since these two symbols are hard to type on my laptop keyboard (*facepalm*), I typed Not instead. Learned a thing. At least :)
 
I think understanding the precedence of the bool not is easier to understand in some other languages because of the way it's usually written, let's take a generic C-style language for instance...

PHP:
if (!1 == 2) print("THIS WILL NEVER BE TRUE!");

When written like this it makes it clearer that 1 is negated before comparison in my opinion. Someone should write up a precedence chart for Monkey. Just copy this one https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence and switch it out with Cerberus' stuff.
 
Sounds like a good idea.

Maybe the Operators article in the docs is already precedence-ordered. Ah yes, there it is; stated in the footnote of the table. I didn't expect to find the precedence chart under Expressions. A separate entry (in the docs outline) would be nice.
 
In my opinion the whole language reference should be split into seperate pages for each topic. Too much scrolling..
 
Back
Top Bottom