
getPosition() & setPosition()
getPosition() & setPosition()
hello, I hoped that getPosition() is returning array [1]:X [2]:Y (elevation has its own function) but it doesn't. Any manipulation with this variable as an array doesn't seem to work. It returns only X position so how can I get thy Y coordinate please 

Last edited by Jouki on Fri Nov 14, 2014 12:42 am, edited 3 times in total.
Re: getPosition()
Multiple return values are different from a table return value. Try
Code: Select all
local x, y = object:getPosition()
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: getPosition()
Hi , u can use local variables to stock x and y of an objects like in thios example :
function returnXY()
local x = dungeon_pressure_plate_35.x
local y = dungeon_pressure_plate_35.y
print ("x= ",x," y= ",y)
end
function returnXY()
local x = dungeon_pressure_plate_35.x
local y = dungeon_pressure_plate_35.y
print ("x= ",x," y= ",y)
end
Re: getPosition()
oh so that's how it works, thanksminmay wrote:Multiple return values are different from a table return value. TryCode: Select all
local x, y = object:getPosition()

EDIT: ok it doesn't work or maybe I'm missing something
yeah that's a way tooFaerghail wrote:Hi , u can use local variables to stock x and y of an objects like in thios example :
function returnXY()
local x = dungeon_pressure_plate_35.x
local y = dungeon_pressure_plate_35.y
print ("x= ",x," y= ",y)
end

Re: getPosition()
Works for me
Prints out the values correctly. What error are you getting?
Code: Select all
local posx, posy, pose, posl = object_test:getPosition()
print (posx, posy, pose, posl)
Re: getPosition()
Scotty wrote:Works for me
Prints out the values correctly. What error are you getting?Code: Select all
local posx, posy, pose, posl = object_test:getPosition() print (posx, posy, pose, posl)
i see, I was in hurry so I haven't try with more variables (with all 4) so that's it
Re: getPosition()
Code: Select all
local x1,y1,e1,l1 = trigger_stone_01:getPosition()
local x2,y2,e2,l2 = trigger_stone_02:getPosition()
print(x2)
print(y2)
Re: getPosition()
That should be working. I just tried the following and it works. Note that it returns the X-coordinate, Y-coordinate and then direction (facing) of the GameObject you call it on.Jouki wrote:am I doing it right? because it doesn't seem to work (still getting only first coordinate)Code: Select all
local x1,y1,e1,l1 = trigger_stone_01:getPosition() local x2,y2,e2,l2 = trigger_stone_02:getPosition() print(x2) print(y2)
Code: Select all
local x1, y1, d1 = party:getPosition()
print(x1, y1, d1)
15 4 2
Which is the correct location and facing (south) of my party.
Re: getPosition() & setPosition()
I've tried set position to this stone but idk what am I doing wrong
variables stonn1 & 2 was made just for sure but it still doesn't work.
Message:
Code: Select all
function resetPuzzle()
local x1,y1,f1 = trigger_stone_01:getPosition()
local x2,y2,f2 = trigger_stone_02:getPosition()
stonn1 = findEntity("stone_1")
stonn2 = findEntity("stone_2")
stonn1:setPosition(5,x1,y1,f1,0,0)
stonn2:setPosition(5,x2,y2,f2,0,0)
end
Message:

-
- Posts: 168
- Joined: Thu Oct 30, 2014 1:56 am
Re: getPosition() & setPosition()
I just tested and I think its better to use getWorldPosition and setWorldPosition instead.
named pressplate "plate1" through "plate8"
named pushableblock floors "trigger1" through "trigger8"
The block instantly teleports to whatever plate you activate.
Code: Select all
function moveblock()
for i = 1,8 do
local activeplate = findEntity("plate"..i)
local activetrigger = findEntity("trigger"..i)
if activeplate.floortrigger:isActivated() then
local pos = activetrigger:getWorldPosition()
block = findEntity("pushable_block_1")
print(pos)
block:setWorldPosition(pos)
end
end
end
named pushableblock floors "trigger1" through "trigger8"
The block instantly teleports to whatever plate you activate.