When somebody does this (script below) … what part of the code is part of the if condition? I normally place a brackets around my code so I know what part counts, but this does not have any, so is it (by default) a first line that comes after only?
ie.
if (!GetIsLocationValid(lDestination))
{
CalcSafeLocation(OBJECT_SELF, lDestination, 2.0, FALSE, FALSE);
}
etc.
Furthermore, I would have thought one needed to put a variable in front of CalcSafeLocation … ?
Yes, there does appear to be quite a bit of “iffy” code in these scripts I am looking through … ankheg from download. I’m guessing it was originally for NWN1 perhaps? I normally have to rewrite a script to understand what someone is trying to do.
So thank you for the explanation. I will add my brackets for clarity and then decide if I am using them or reworking my own version AI. I like some aspects, but much of it appears to be unnecessary.
Don’t know if NWN or NWN2 is relevant. I think we use the same style but what I look here is quite basic. It’s the same as if I write
if condition
expression
if condition 2
expression 2
You don’t need braces when you only have one expression. I hate it though when people do it the way you show. There should at least be an empty line after the expression.
@Lance_Botelle Try my Basics series of tutorials. Yes I know that they are written for NwN 1/NwN EE, but the vast majority of what I have written in them transfers over to NwN 2. What you are asking about here is definitely covered in two of them (in spite of my attempt to not repeat myself ).
@kevL_s Thanks once again for proof-reading them. Any chance you could create a document that covers what is different in NwN2 compared to what I wrote for NwN 1/EE?
Well, I do have some Tutorials in my library and your ones may well be among them, so I may have this info already. Sometimes, though, I find it easier/quicker to just ask and get a response or clarification. That said, maybe I can glance over some of these to get ahead.
The differences in grammar/syntax between 1 and 2 could i think be covered in a single paragraph appendix … the only thing that springs to mind is the quirky bitwise NOT (complement) operator in 1, that was changed to standard c-like expectations in 2.
There might also be some differences between the bitwise shift operations …
Other than that I think all the operator precedence, bracketing formalisms, yada yada is identical.
am sure there’s a thread we had about some of these things ( 1…3 yr ago ) that mentions the quirky ~ operator and its workaround … but can’t find it …
It is good practice to use brackets so that bugs are not introduced when adding lines after the initial design. Also makes it easy to insert debugging lines and not introduce bugs.