Difference between revisions of "Talk:GetPositionX - ObjectReference"

From the CreationKit Wiki
Jump to navigation Jump to search
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)

Revision as of 09:29, 14 January 2019

Getting Cell Coordinates

Ever wondered how you can use the Cell View window's coordinates in game? Simple. You take the two values and you multiply them by 4096. If you want to convert an object's in game coordinates to use in the Cell View window, you divide the X and Y values by 4096 and cast as int to remove the decimals. Lisselli (talk)Lisselli (talk) 2017-10-06T11:57:52 (EDT)

GetCoordinateX

Int Function GetCoordinateX(float afPosX)
; Returns the X coordinate. 

int posX = afPosX as int

	if (posX < 0)
		return (posX / 4096) - 1
	else
		return posX / 4096
	endif

EndFunction

--Rasikko (talk) 2019-01-14T09:29:10 (EST)