• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] A value between values

Status
Not open for further replies.
Level 8
Joined
Nov 9, 2008
Messages
502
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:
Level 8
Joined
Nov 9, 2008
Messages
502
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.
 
Level 8
Joined
Nov 9, 2008
Messages
502
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:
Level 8
Joined
Nov 9, 2008
Messages
502
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!!!!!
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
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.
 
Level 8
Joined
Nov 9, 2008
Messages
502
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.
 
Level 8
Joined
Nov 9, 2008
Messages
502
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 8
Joined
Nov 9, 2008
Messages
502
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.
Top