Difference between revisions of "Talk:GetPositionX - ObjectReference"

Jump to navigation Jump to search
→‎GetCoordinateX: Corrected the math.
imported>Rasikko
imported>Rasikko
(→‎GetCoordinateX: Corrected the math.)
Line 6: Line 6:
== GetCoordinateX ==
== GetCoordinateX ==
<source lang="papyrus">
<source lang="papyrus">
Int Function GetCoordinateX(ObjectReference akRef)
Int Function GetCoordinateX(float afPosX)
    ; Converts the objects' position to the X coordinate of the cell.
; Returns the X coordinate.  
    Float GetPosX = akRef.GetPositionX()
 
    If GetPosX >= 0.0
int posX = afPosX as int
        Return GetPosX as int
 
    Else
if (posX < 0)
        Return Math.Floor(GetPosX)
return (posX / 4096) - 1
    EndIf
else
return posX / 4096
endif
 
EndFunction
EndFunction
</source>
</source>
Use this to get the exact X coordinate for the cell. To be used only for exterior cells. Takes negative values into account. [[User:Lisselli|Lisselli]] ([[User talk:Lisselli|talk]]) 2017-10-27T12:22:34 (EDT)
--[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2019-01-14T09:29:10 (EST)
: Math.Floor would give an inaccurate coordinate. If Y is -14.2, Floor will put it to -15. To properly handle positive and negatives in the case of coordinates, simply casting as int will do and no need to check if the position is negative or positive. --[[User:Rasikko|Rasikko]] ([[User talk:Rasikko|talk]]) 2018-01-10T12:39:49 (EST)
Anonymous user

Navigation menu