getPosition() & setPosition()

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

getPosition() & setPosition()

Post 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:
Last edited by Jouki on Fri Nov 14, 2014 12:42 am, edited 3 times in total.
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: getPosition()

Post by minmay »

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.
Faerghail
Posts: 72
Joined: Tue Mar 27, 2012 8:49 pm

Re: getPosition()

Post 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
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: getPosition()

Post 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 :)
Scotty
Posts: 69
Joined: Fri Nov 07, 2014 2:59 pm

Re: getPosition()

Post 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?
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: getPosition()

Post 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
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: getPosition()

Post 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)
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: getPosition()

Post 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.
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: getPosition() & setPosition()

Post 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
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: getPosition() & setPosition()

Post 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.
Post Reply