Author Topic: OR operator ?  (Read 318 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OR operator ?
« on: February 27, 2011, 03:43:19 pm »


               Is their an OR operator in NWN scripting? I haven't been able to find anything in the lexicon.

example..

if (GetTag(oItem) != "item1" OR "item2")
        {
         DestroyObject(oItem);
         }
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
OR operator ?
« Reply #1 on: February 27, 2011, 03:49:14 pm »


               Yes. It's done as "||".

string sTag = GetTag(oItem);              /* I do this here to avoid redundant calls to get the item's tag. */
if (sTag != "item1" || sTag != "item2")
   {
   DestroyObject(oItem);
   }

So...if the tag does not equal "item1", destroy the item.
or it the tag does not equal "item2", destroy the item.
Looks like the item is getting destroyed no matter what.

-------------------------------------

There is also a version of AND. It's done as "&&".  And it sounds closer to what it looks like you want in your code snippet, since both conditions need to be met for the item to be destroyed, rather than just one of them.

string sTag = GetTag(oItem);              /* I do this here to avoid redundant calls to get the item's tag. */
if (sTag != "item1" && sTag != "item2")
   {
   DestroyObject(oItem);
   }

If the tag does not equal "item1" and the tag does not equal "item2", then destroy the item.
               
               

               


                     Modifié par The Amethyst Dragon, 27 février 2011 - 03:58 .
                     
                  


            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
OR operator ?
« Reply #2 on: February 27, 2011, 03:52:27 pm »


               I think this will help... not tested though.

if (GetTag(oItem) != "item1" || GetTag(oItem) !="item2")

And "AD" beats me to the punch .. '<img'>
               
               

               


                     Modifié par kalbaern, 27 février 2011 - 03:53 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OR operator ?
« Reply #3 on: February 27, 2011, 04:30:37 pm »


               Thanks guys. I knew their had to be something to handle the OR.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OR operator ?
« Reply #4 on: February 27, 2011, 04:31:21 pm »


               (doublepost) .
               
               

               


                     Modifié par Buddywarrior, 27 février 2011 - 04:31 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
OR operator ?
« Reply #5 on: February 27, 2011, 05:12:50 pm »


               Here is the lexicon page, Just encase you still wanted to see it.
Logical Operators/Truth Tests