scripting: negation, if !(true), if not (x), etc.

Post » Thu May 19, 2011 9:21 am

So, I know how to determine if a form IS in a formlist:
if ref.IsInList FormList


But how do I determine that it is NOT? How do I negate boolean values? I've tried:
if !(ref.IsInList FormList)


but that's apparently invalid. I've tried searching for an answer, but I get dozens of pages of unrelated stuff.

EDIT: seems that boolean values are actually just single bit integers, meaning value is 1 or 0. So, I should do:
if 1 - (ref.IsInList FormList)


right?
User avatar
FABIAN RUIZ
 
Posts: 3495
Joined: Mon Oct 15, 2007 11:13 am

Post » Thu May 19, 2011 12:02 am

Personally, I'd do
if ref.IsInList FormList == 0
in case it returns a non-zero value besides 1. Not necessarily for this case in particular, but as a negative result check to use with nearly any function.

Queue
User avatar
Kat Lehmann
 
Posts: 3409
Joined: Tue Jun 27, 2006 6:24 am

Post » Wed May 18, 2011 6:12 pm

There's no proper boolean functions per se, they just return 1 or 0 so comparing values works. Also of note, Haama (IIRC) did some pretty heavy testing and discovered it's a little more efficient to do
if(Thing)else   STUFFendif

than
if(Thing == 0)   STUFFendif

User avatar
Kate Murrell
 
Posts: 3537
Joined: Mon Oct 16, 2006 4:02 am

Post » Thu May 19, 2011 5:55 am

Good to know; I've been brutally optimizing my script, and will add that to the list of things to do.

I'm surprized, because the test would be the same in assembly either way; I guess to compare to 0 in this scripting language is more costly.

Edit - to elaborate:

say, in a given programming language, you put
.if x == 0
;do stuff
.endif

that would translate to
cmp x, 0
jne @endif
;do stuff
@endif:

and to compare
.if x
;do stuff
.endif

would be
cmp x, 0
je @endif
;do stuff
@endif:

So the only difference is the type of jump, but the comparison would be done the same way.

Queue
User avatar
Jaki Birch
 
Posts: 3379
Joined: Fri Jan 26, 2007 3:16 am

Post » Thu May 19, 2011 7:34 am

Given what was stated above, I think it's like so:

"if (x==0)" seems to be doing 2 comparisons. There's the contents, (x==0), which is itself a comparison operation. We'll call the result A. The if statement then does another comparison operation on the result: (A != 0). So, I'm thinking what actually is happening: ( ( x == 0 ) != 0 ). 2 comparison operations here rather than 1. You're right, Queue, it would be more efficient in assembly, but this is a high level language :P
User avatar
Red Sauce
 
Posts: 3431
Joined: Fri Aug 04, 2006 1:35 pm


Return to Fallout: New Vegas