Page 1 of 2

getPosition() & setPosition()

Posted: Wed Nov 12, 2014 1:21 am
by Jouki
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 :roll:

Re: getPosition()

Posted: Wed Nov 12, 2014 1:31 am
by minmay
Multiple return values are different from a table return value. Try

Code: Select all

local x, y = object:getPosition()

Re: getPosition()

Posted: Wed Nov 12, 2014 1:33 am
by Faerghail
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()

Posted: Wed Nov 12, 2014 9:56 am
by Jouki
minmay wrote:Multiple return values are different from a table return value. Try

Code: Select all

local x, y = object:getPosition()
oh so that's how it works, thanks :)

EDIT: ok it doesn't work or maybe I'm missing something
Faerghail 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
yeah that's a way too :)

Re: getPosition()

Posted: Wed Nov 12, 2014 4:11 pm
by Scotty
Works for me

Code: Select all

local posx, posy, pose, posl = object_test:getPosition()
print (posx, posy, pose, posl)
Prints out the values correctly. What error are you getting?

Re: getPosition()

Posted: Wed Nov 12, 2014 8:59 pm
by Jouki
Scotty wrote:Works for me

Code: Select all

local posx, posy, pose, posl = object_test:getPosition()
print (posx, posy, pose, posl)
Prints out the values correctly. What error are you getting?

i see, I was in hurry so I haven't try with more variables (with all 4) so that's it

Re: getPosition()

Posted: Thu Nov 13, 2014 2:08 am
by Jouki

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)
am I doing it right? because it doesn't seem to work (still getting only first coordinate)

Re: getPosition()

Posted: Thu Nov 13, 2014 2:57 am
by MrChoke
Jouki wrote:

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)
am I doing it right? because it doesn't seem to work (still getting only first coordinate)
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.

Code: Select all

local x1, y1, d1 = party:getPosition()
	print(x1, y1, d1)
It printed:
15 4 2

Which is the correct location and facing (south) of my party.

Re: getPosition() & setPosition()

Posted: Fri Nov 14, 2014 1:06 am
by Jouki
I've tried set position to this stone but idk what am I doing wrong

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
variables stonn1 & 2 was made just for sure but it still doesn't work.

Message: Image

Re: getPosition() & setPosition()

Posted: Fri Nov 14, 2014 3:20 am
by GoldenShadowGS
I just tested and I think its better to use getWorldPosition and setWorldPosition instead.

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 pressplate "plate1" through "plate8"
named pushableblock floors "trigger1" through "trigger8"

The block instantly teleports to whatever plate you activate.