HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Using 'And' and 'Or' booleans together correctly?

04-03-2010, 04:41 PM#1
Ignitedstar
This is very peculiar, because I've always got it to work in GUI, but this was a long time ago. In JASS, it seems like the code doesn't read like I think it should.

I'm having some trouble using 'And' and 'Or' booleans together. Let me make a simple examples to explain what I know and what confounds me.

This is what I know:
Collapse JASS:
function Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'Hpal' or GetSpellAbilityId() == 'Hmkg'
endfunction

This says that the condition returns true only for the Paladin and Mountain King. As for and:
Collapse JASS:
function Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'Hpal' and GetWidgetLife(GetTriggerUnit()) <= 300.
endfunction

This says that the condition returns true only by the Paladin when his life is below 300. Let's say that I don't want the Mountain King to use this ability either when his life is below 300. So, I thought this would work:
Collapse JASS:
function Conditions takes nothing returns boolean
    return GetWidgetLife(GetTriggerUnit()) <= 300. and (GetUnitTypeId(GetTriggerUnit()) == 'Hpal' or GetUnitTypeId(GetTriggerUnit()) == 'Hmkg')
endfunction

However, now both the Paladin and the Mountain King can't use this ability at all? I always thought that parenthesis made that much of a difference, but it seems like they are being discounted? What exactly am I doing wrong, and how I can fix it? I'm trying to use as little lines as possible, because I have to do this about 30 times.
04-03-2010, 04:52 PM#2
Ammorth
You want the statement to be true when you want it to work. Your comparison for health returns true when the hero has less than or equal to 300 health. So they will only cast the spell when they have are below 300 health.
04-03-2010, 06:36 PM#3
Ignitedstar
Yeah, I know that. However, it seems that whenever I have the Paladin or the Mountain King at below 300, this ability doesn't work for either of them.

While the booleans are just a substitute for my actual case, the and's and or's are in the same positions have I am currently using them. Except one thing... One of the booleans I'm using checks for a string, but that shouldn't matter (if it does, tell me).

EDIT: Nevermind. I did something awfully stupid.

EDIT 2: Nevermind on the nevermind... I'm back at where I started. Okay... Now I feel twice as stupid.

EDIT 3: Nevermind times three. I found a solution that I didn't really want, but it's acceptable. Thanks, though.