• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Why is this like this?

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
JASS:
if (!UnitHasItemOfTypeBJ(u, 'I00Z') == false || !UnitHasItemOfTypeBJ(u, 'I00J') == false)  {

   }
   else
   {
   DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Yes");
    SetUnitState(u, UNIT_STATE_MANA, currMana);
   
   }
   
  }

So I added the else because for some reason regardless if I set false or true or != true, etc. It would always run even though I had the item, and when I didn't have the item it wouldn't run.

Before I had this

if (UnitHasItemOfTypeBJ(u, 'I00Z') != true|| UnitHasItemOfTypeBJ(u, 'I00J') != true) {

I had the item, and it would still run the code. And now I added the !unithasitem part, and it still runs it and I needed to add the else statement. Why is that? Am I reading this incorrectly? Sorry if this is confusing not sure how to explain it better.
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
This does not look like JASS... what language are you using ?

You got way too many turnarounds in that comparison. It makes me confused what you are trying to achieve. Mind explaining ?

if you want it to fire if a unit has the item just do:

Code:
//This is how it would look like... yours look like C-kinda language.
if ( UnitHasItemOfTypeBJ(u, 'I00Z') || UnitHasItemOfTypeBJ(u, 'I00J') )
{
  //Unit has either items
}
else
{
  //Unit has neither items
}

JASS:
//Jass should be like:
if ( UnitHasItemOfTypeBJ(u, 'I00Z') || UnitHasItemOfTypeBJ(u, 'I00J') ) //Shouldn't "||" be "or" instead ?
then
  //Unit has either item here
else
  //unit has no item here
endif

regards
-Ned
 
Last edited:
Level 16
Joined
Mar 25, 2016
Messages
1,327
Looks like zinc to me.
The boolean logic here is very complicated.
!A == false || !B== false
A == true || B == true
A || B
now with the else you turn it around
! (A || B)
!A && !B

it's all the same, just the last two are a lot more readable and more efficient, if the code is not optimized
 
Level 12
Joined
Dec 2, 2016
Messages
733
Yeah it's zinc, but it's weird cause I had it like (UnitHasItemOfTypeBJ(u, 'I00Z') == true)

And if the unit didn't have the item it would run the statement, and if I set it to false, it would also run the statement even if I did or didnt have the item. And the only way it didn't when I added the else part.
 
Status
Not open for further replies.
Top