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

Re: getPosition() & setPosition()

Post by Scotty »

Jouki wrote: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
The values to pass to setPosition go: x, y, facing, elevation, level. Facing being a number 0 - 3, and level being the level_index which will always be > 0. You're using y as elevation, with a level_index that doesn't exist. Try this:

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(x1,y1-1,0,0,1)
	stonn2:setPosition(x2,y2-1,0,0,1)
end
That should return the stones 1 square north of the triggers.
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: getPosition() & setPosition()

Post by Jouki »

Scotty wrote:
Jouki wrote: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
The values to pass to setPosition go: x, y, facing, elevation, level. Facing being a number 0 - 3, and level being the level_index which will always be > 0. You're using y as elevation, with a level_index that doesn't exist. Try this:

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(x1,y1-1,0,0,1)
	stonn2:setPosition(x2,y2-1,0,0,1)
end
That should return the stones 1 square north of the triggers.
thanks, works perfectly!
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: getPosition() & setPosition()

Post by Jouki »

I've got interesting effect, I had a stone on coords for example 10,13 and I moved him onto 10,12 after reseting the stones it appear on right position but at the [10,12] is still invisible obstacle of the stone. actaully it "copied" so now I have obstacle at 10,13 (the stone, visible) and 10,12 where it was before reseting (setting the position) and as I said it's invisible, not a proper clone of the object "stone"

EDIT: maybe I should try destroy them and spawn them again on that position
User avatar
Mentok
Posts: 5
Joined: Sat Dec 27, 2014 6:34 am

Re: getPosition() & setPosition()

Post by Mentok »

Jouki wrote:I've got interesting effect, I had a stone on coords for example 10,13 and I moved him onto 10,12 after reseting the stones it appear on right position but at the [10,12] is still invisible obstacle of the stone. actaully it "copied" so now I have obstacle at 10,13 (the stone, visible) and 10,12 where it was before reseting (setting the position) and as I said it's invisible, not a proper clone of the object "stone"

EDIT: maybe I should try destroy them and spawn them again on that position
I ran into the same problem. It seems like the .dynamicobstacle component gets left behind somehow. I just went the destroy and spawn route and that seems to be working fine so far.

function puzzreset()

pushable_block_1:destroy()
pushable_block_2:destroy()
spawn("pushable_block", 4, 19, 23, 1, -1, "pushable_block_1")
spawn("pushable_block", 4, 20, 23, 1, -1, "pushable_block_2")

end
Post Reply