# [JASS]A value between values

Status
Not open for further replies.

#### toofless

Level 8
MASS EDIT:

Hi. So basicly I'm writing a collision check which uses GroupEnumUnitsInRange() with a filterfunc. Here is my filter:

JASS:
``````function Filter takes nothing returns boolean
local unit u = GetFilterUnit() // unit in area
local unit ut = udg_u[udg_i] // subject
local real yu = GetUnitFlyHeight(u)
local real yut = GetUnitFlyHeight(ut)
local real utp = yu + udg_yv[udg_i] + udg_ya // projected fly height
local boolean a = GetOwningPlayer(u) == Player(11)
local boolean b = yu >= yut and yu <= utp
local boolean c = yu <= yut and yu >= utp
local boolean d = b == true or c == true
local boolean e = d == true and a == true
set u = null
set ut = null
return e
endfunction``````

Now the math denotes that unless the filter unit is between the 2 values it won't be added to the group. Later I count the units in the group and if it's greater than 0 then I register a collision EXCEPT that for some reason this filterfunc always returns true.

What have I missed?
Thankyou in advance and ofcourse rep if you are deserving.

I attached the map incase it helps. Beware! It is in a very early stage.

Please, any ideas why this filterfun returns true when it shouldn't?

#### Attachments

• Smash Brothers v.0.01.w3x
22.8 KB · Views: 36
Last edited by a moderator:

#### Reaper2008

Level 12
Please don't bump that much. Why use all that s*** to form one mega-boolean, when you can return a == true , and b == true, and c == true, and d == true etc?

#### toofless

Level 8
Huh?

You can only return 1 value.....

I know I can put all those arguments on 1 line but I think it's easier to read like this. Also, they are not all ANDS.

Whichever way it is written, the logic is still there but still it always returns true... it's puzzling.

#### Ciebron

Level 11
JASS:
``local boolean ok = (GetOwningPlayer(u) == Player(11)) and (yu >= yut and yu <= utp) or (yu <= yut and yu >= utp)``

woho -4 booleans

#### toofless

Level 8
v.v that wasn't really the issue

give yourself a medal though

i bet you can't tell me why it still returns true

Last edited:

#### Ciebron

Level 11
EDIT: Nevermind, Brain error

#### GhostWolf

Level 29
It returns true because the conditions always evaluate to 'true'.

But seriously, it's not as if we (or at least me) can understand anything from those very clear variable names.
It only shows you how much names matter, even in a 10-liner function.

#### Element of Water

Level 18
what's udg_yv? I understand the rest.

#### toofless

Level 8
udg_yv = velocity over y axis

Anyway, thanks all for the help. I managed to fix it.

It returns true because the conditions always evaluate to 'true'.

No, they do not. That is what was confusing me. I actualy plugged the other booleans into a function that loops through all units in the group, just like the boolexpr but for some rason it doesn't work in the boolexpr but does in an indepenent function. STRANGE. So what I needed you to tell me that Boolexprs hav their limits!!!!!

#### Eleandor

Level 21
you probably need to use brackets in d == true and a == true

JASS:
``````function Filter takes nothing returns boolean
local real yu = GetUnitFlyHeight(GetFilterUnit())
local real yut = GetUnitFlyHeight(udg_u[udg_i])
local real utp = udg_yv[udg_i] + udg_ya
return (GetOwningPlayer(GetFilterUnit()) == Player(11)) and ((yu >= yut and (utp > 0)) or (yu <= yut and (utp < 0)))
endfunction``````

If that doesn't work, use debug messages before "returning" to see which statements hold true that shouldn't hold true.

#### toofless

Level 8
I know Eleandor and that is how I first wrote it (because that is the most efficient way as people have noticed). The weird thing is when I took out all the booleans except player check and put them in another function, they work. Do boolexprs have limits like this?

I will debug for a laugh.

#### Eleandor

Level 21
I think your error may be here:

local boolean d = b == true or c == true

It's read as "b == (true or c) == true
true or c is always true.
true == true is true
Maybe it's something fishy like that

#### toofless

Level 8
I debuged to show the bool if they are true and I got this sequence:
c
d
a
c
d
e

So bool c is the problem because it should not have been true, and making the others return true...what the problem was I do not know.

Level 21
sequence?

#### toofless

Level 8
Ye it is periodic.

JASS:
``````function myFilter takes nothing returns boolean
local unit u = GetFilterUnit() // unit in area
local unit ut = udg_u[udg_i] // subject
local real yu = GetUnitFlyHeight(u)
local real yut = GetUnitFlyHeight(ut)
local real utp = yu + udg_yv[udg_i] + udg_ya // projected fly height
local boolean a = GetOwningPlayer(u) == Player(11)
local boolean b = yu >= yut and yu <= utp
local boolean c = yu <= yut and yu >= utp
local boolean d = b == true or c == true
local boolean e = d == true and a == true
if a == true then
call DisplayTextToPlayer(Player(0), 0, 0, "a")
endif
if b == true then
call DisplayTextToPlayer(Player(0), 0, 0, "b")
endif
if c == true then
call DisplayTextToPlayer(Player(0), 0, 0, "c")
endif
if d == true then
call DisplayTextToPlayer(Player(0), 0, 0, "d")
endif
if e == true then
call DisplayTextToPlayer(Player(0), 0, 0, "e")
endif
call DisplayTextToPlayer(Player(0), 0, 0, "break")
set u = null
set ut = null
return e
endfunction``````

Actualy the sequence was
a
c
d
e
break
c
d
break
...repeat...

Ahh the second part is because of the initial unit (not Player(11)).
Still it does not explain why c returns true always....

It should work in the filter no? I don't understand.

Status
Not open for further replies.

Replies
16
Views
1K
Replies
5
Views
1K
[JASS] Just Checking
Replies
29
Views
1K
Replies
8
Views
761
Replies
5
Views
555