[RELz] Operators

Post » Sat May 07, 2011 1:36 am

Many novice scripters seem to misunderstand the function of the comparison and logical operators available in Fallout 3 scripting, and many more seem completely unaware of the modulo operator. I've written a tutorial describing the function of each available operator, including a hierarchical list showing which operators will be evaluated first.

http://www.cipscis.com/fallout/tutorials/operators.aspx

Cipscis
User avatar
Kristian Perez
 
Posts: 3365
Joined: Thu Aug 23, 2007 3:03 am

Post » Sat May 07, 2011 5:39 am

Nice job one again Cipscis! Though I am a rather experienced scripted (Or like to believe so :P) this is still great review and a big help. I did not know operators had priorities within scripting calculation. How on earth did you find this order out?
User avatar
scorpion972
 
Posts: 3515
Joined: Fri Mar 16, 2007 11:20 am

Post » Sat May 07, 2011 1:14 am

Thanks!

When it came to figuring out the correct priorities I did quite a few tests in the console using different expressions to see which operators were evaluated first. Here's the record that I have in my development folder:
Spoiler
==========================* %2 * 3 % 2(2 * 3) % 2 = 6 & 2 = 0 *2 * (3 % 2) = 2 * 1 = 23 % 1 * 2(3 % 1) * 2 = 0 * 2 = 0 *3 % (1 * 2) = 3 % 2 = 1==========================* ==3 * 1 == 1(3 * 1) == 1 = 3 == 1 = 0 *3 * (1 == 1) = 3 * 1 = 31 == 1 * 3(1 == 1) * 3 = 1 * 3 = 31 == (1 * 3) = 1 == 3 = 0 *============================ !=3 == 1 != 1(3 == 1) != 1 = 0 != 1 = 1 *3 == (1 != 1) = 3 == 0 = 01 != 1 == 3(1 != 1) == 3 = 0 == 3 = 0 *1 != (1 == 3) = 1 != 0 = 1============================ >0 == 0 > 1(0 == 0) > 1 = 1 > 1 = 0 *0 == (0 > 1) = 0 == 0 = 10 > 0 == 0(0 > 0) == 0 = 0 == 0 = 1 *0 > (0 == 0) = 0 > 1 = 0==========================> >=0 > 0 >= 0(0 > 0) >= 0 = 0 >= 0 = 1 *0 > (0 >= 0) = 0 > 1 = 01 >= 1 > 1(1 >= 1) > 1 = 1 > 1 = 0 *1 >= (1 > 1) = 1 >= 0 = 1==========================< <=1 < 1 <= 1(1 < 1) <= 1 = 0 <= 1 = 1 *1 < (1 <= 1) = 1 < 1 = 00 <= 0 < 0(0 <= 0) < 0 = 1 < 0 = 0 *0 <= (0 < 0) = 0 <= 0 = 1==========================< >0 < 2 > 1(0 < 2) > 1 = 1 > 1 = 0 *0 < (2 > 1) = 0 < 1 = 12 > 1 < 0(2 > 1) < 0 = 1 < 0 = 0 *2 > (1 < 0) = 2 > 0 = 1==========================< ||1 < 0 || 1(1 < 0) || 1 = 0 || 1 = 1 *1 < (0 || 1) = 1 < 1 = 01 || 1 < 0(1 || 1) < 0 = 1 < 0 = 01 || (1 < 0) = 1 || 0 = 1 *==========================> ||0 > 1 || 1(0 > 1) || 1 = 0 || 1 = 1 *0 > (1 || 1) = 0 > 1 = 01 || 1 > 1(1 || 1) > 1 = 1 > 1 = 01 || (1 > 1) = 1 || 0 = 1 *==========================|| &&1 || 0 && 0(1 || 0) && 0 = 1 && 0 = 0 *1 || (0 && 0) = 1 || 0 = 10 && 0 || 1(0 && 0) || 1 = 0 || 1 = 10 && (0 || 1) = 0 && 1 = 0 *==========================
The structure of each test is:
  • Operators being compared
  • First expression being used
  • Possible ways in which the expression could be evaluated - a * is next to the one that occurred
  • Second expression being used
  • Possible ways in which the expression could be evaluated - a * is next to the one that occurred

I used two expressions because if the operators had the same priority then they would simply be evaluated left to right. If the same operator was evaluated first in both expressions, then I gave it higher priority. If the left-most operator was evaluated first in both expressions, I gave them the same priority.

Cipscis
User avatar
GRAEME
 
Posts: 3363
Joined: Sat May 19, 2007 2:48 am

Post » Fri May 06, 2011 6:02 pm

Wow that is crazy. Again, great work.
User avatar
Milagros Osorio
 
Posts: 3426
Joined: Fri Aug 25, 2006 4:33 pm

Post » Fri May 06, 2011 10:08 pm

Agree this is a Nice article! Its a great reference chart for anyone scripting IMHO.

Cheers! :goodjob:
User avatar
Lizzie
 
Posts: 3476
Joined: Sun Nov 19, 2006 5:51 am

Post » Sat May 07, 2011 2:34 am

Great Article, loved it, Thanks

Thanks Persidon
User avatar
Antony Holdsworth
 
Posts: 3387
Joined: Tue May 29, 2007 4:50 am

Post » Sat May 07, 2011 4:46 am

Hey Jesus! ...I mean Cispscis.
User avatar
Lyd
 
Posts: 3335
Joined: Sat Aug 26, 2006 2:56 pm


Return to Fallout 3