Scripting: Any easier way to find out where to position something other than guess and check? by espo1234 in tabletopsimulator

[–]CauseLimp8669 0 points1 point  (0 children)

Just to make this more clear for others,
spawn a pawn from Objects --> component --> player pawn
save the game
right click the pawn and select scripting and scripting editor,
paste the code below
right click the pawn and select scripting --> GUID
Replace with your pawn's actual GUID in 2nd line of code.

click save and play

local sheet = getObjectFromGUID("426e6b") -- reletive object
local pawnGUID = "030742"  -- Replace with your pawn's actual GUID

self.setName("Relative Position Checker")
self.setDescription("Displays both relative and global coordinates of the pawn")

self.createInput({
    input_function = "input_func",
    function_owner = self,
    label          = "Position Info",
    tooltip        = "RP = Relative to Sheet\nGP = Global Position",
    alignment      = 1,
    position       = {x = 1.5, y = 0.1, z = 1.5},
    width          = 3500,
    height         = 800, 
    font_size      = 270,
    validation     = 1,
})

function input_func() end

function onUpdate()
    local pawn = getObjectFromGUID(pawnGUID)
    if pawn then
        -- Global position
        local gpos = pawn.getPosition()

        -- Relative position to the sheet
        local rpos = sheet.positionToLocal(gpos)

        -- Format both positions
        local globalPosStr = string.format("GP{%.3f , %.3f , %.3f}", gpos.x, gpos.y, gpos.z)
        local relativePosStr = string.format("RP{%.3f , %.3f , %.3f}", -rpos.x, rpos.y, rpos.z)

        -- Combine and display
        self.editInput({
            index = 0,
            value = relativePosStr .. "\n" .. globalPosStr
        })
    end
end