function return problem

Xbing

New Member
Reaction score
0
i have this function used for a boolexpr that does this:
JASS:
    private function lockcond takes nothing returns boolean
        local location compareloc1 = GetUnitLoc(MissleDummy)
        local location compareloc2 = GetUnitLoc(GetFilterUnit())
        return(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and ((GetUnitFacing(MissleDummy) - 90) <= AngleBetweenPoints(compareloc1, compareloc2) and (GetUnitFacing(MissleDummy) + 90) >= AngleBetweenPoints(compareloc1, compareloc2)))
        call RemoveLocation(compareloc1)
        call RemoveLocation(compareloc2)
    endfunction

however, jasshelper always tells me i have a missing return at the last line of the endfunction. is it true that the return must always be at the bottom?:eek: and if it needs to be, how can i remove the locations after use then?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Use X and Y instead, so you don't need to null it and care about the leaking problem.
For your script, the location is leaking everywhere.
 

Xbing

New Member
Reaction score
0
what do you mean by its leaking everywhere? how do i avoid it and how to use X and Y without leaking?:confused:
 

Jedi

New Member
Reaction score
63
return, stops the function, so locations won't removed.

JASS:
private function lockcond takes nothing returns boolean
        local location compareloc1 = GetUnitLoc(MissleDummy)
        local location compareloc2 = GetUnitLoc(GetFilterUnit())
        local boolean b = (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and ((GetUnitFacing(MissleDummy) - 90) <= AngleBetweenPoints(compareloc1, compareloc2) and (GetUnitFacing(MissleDummy) + 90) >= AngleBetweenPoints(compareloc1, compareloc2)))
        call RemoveLocation(compareloc1)
        call RemoveLocation(compareloc2)
        set compareloc1 = null
        set compareloc2 = null
        return b
  endfunction


use what Laiev posted, coordinates are just numbers so you don't need to remove or null them.
 

Laiev

Hey Listen!!
Reaction score
188

Xbing

New Member
Reaction score
0
JASS:
private function lockcond takes nothing returns boolean
        local real cx = GetUnitX(MissleDummy)
        local real cy = GetUnitY(MissleDummy)
        local real tx = GetUnitX(GetFilterUnit())
        local real ty = GetUnitY(GetFilterUnit())
        local real angle = bj_RADTODEG * Atan2(ty-cy, tx-cx)  
        return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and ((GetUnitFacing(MissleDummy) - 90) <= angle and (GetUnitFacing(MissleDummy) + 90) >= angle)
    endfunction


I think it should work

i kind of understand everything except for the Atan2. what does it actually do? im no math genius but does that get the tan of 2 points?

*edit and why did jedi null the locations even after he removed them
 

Laiev

Hey Listen!!
Reaction score
188
>>i kind of understand everything except for the Atan2. what does it actually do? im no math genius but does that get the tan of 2 points?

Idk exactly what Atan2 is... probably some other guy can do it... but i know that is this way that you check angle between coordinates... also the bj_RADTODEG is to convert the angle to the format angle of warcraft (or something related to this)

>> edit and why did jedi null the locations even after he removed them

because local variable need to be nulled :p except real and integer you don't need...
 

Xbing

New Member
Reaction score
0
>>because local variable need to be nulled except real and integer you don't need...

does it need to be nulled because it will leak or because it will affect the values later? and anyway if thats the truth ill have to start CPing nulls around my whole map...
 

Trollvottel

never aging title
Reaction score
262
i kind of understand everything except for the Atan2. what does it actually do? im no math genius but does that get the tan of 2 points?

its just the tangent function with 2 values taken.
normally you would do Atan(dy/dx) to get the angle:
Neu Bitmap.JPG

But as you will maybe realize, there will a bug if dx is 0 because then The operation dy/dx cant be executed. Also the angles given will always be between -90° and +90° since you only get the rate of dy and dx while not knowing which value they have in detail.
Thats why the function Atan2 was created. It allows you to get angles between -180° and 180° and is thus more useful to determine the angle between 2 points.
also the bj_RADTODEG is to convert the angle to the format angle of warcraft (or something related to this)
The warcraft trigonometric functions work with radians while GUI users work with degrees. 360° match 2*Pi. So to convert Degrees to Radians we have [ljass]bj_DEGTORAD[/ljass] and to convert Radians to Degrees we have [ljass]bj_RADTODEG[/ljass]
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top