Aller au contenu

Photo

OR operator ?


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
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);
         }

#2
The Amethyst Dragon

The Amethyst Dragon
  • Members
  • 1 882 messages
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 .


#3
kalbaern

kalbaern
  • Members
  • 824 messages
I think this will help... not tested though.

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

And "AD" beats me to the punch .. :D

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


#4
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
Thanks guys. I knew their had to be something to handle the OR.

#5
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
(doublepost) .

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


#6
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Here is the lexicon page, Just encase you still wanted to see it.
Logical Operators/Truth Tests