Moving item from one pedestial to the next

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!
Torquemada
Posts: 25
Joined: Fri Apr 05, 2013 10:52 pm

Moving item from one pedestial to the next

Post by Torquemada »

Hi I am currently trying to do the following:
- Put items on Pedestial1
- When correct items are placed on Pedestial1 they will be removed and the contents of Pedestial2 will be placed on Pedestial1

This is what I have currently:

Code: Select all

		for i,v in pedestial1.surface:contents() do
			v.go:destroyDelayed()
		end
		for i,v in pedestial2.surface:contents() do
			v.go:destroyDelayed()
		end
		pedestial1.surface:addItem(spawn("some_item").item) -- Here I get Stack overflow when run
So basicly I am removing all items on Pedestial1 and Pedestial2 then spawning a new item that was on Pedestial2 and placing it on Pedestial1, however when I try to place the item (last line of the code) I get stack overflow error.
Is there perhaps a better way to clear the contents of a surface and moving an item from one to the next?
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Moving item from one pedestial to the next

Post by Pompidom »

Is it a one time event?
Is the item that you're placing 1 specific item?
Does the placed item have to swap back afterwards?

If it doesn't need to be swapped back and it's a one time item, you can probably do it with 2 simple destroy - spawn scripts with a counter decrement activating the 2nd destroy and spawn on pedestal 2 script giving the illusion that the items swapped places.

It's clunky, but it might get the job done for now until someone can come up with something more advanced

What I usually do is make super simple scripts I already know.

Here is some code from my dungeon. Place skulls on pedestals and they appear on the wall, the counter decrement activates a counter that activates a 2nd script spawning the crown.

Code: Select all

function Quest2()
	local s = g1_dark_temple_pedestal_1.surface
	for _,e in s:contents() do
		if e.go.name == "fancy_skull" then
			e.go:destroy()
			playSound("secret")
			counter_2.counter:decrement()
			ud_alcove_3.surface:addItem(spawn("fancy_skull").item)
		end
	end
end

Code: Select all

function Quest3()
	local s = g1_dark_temple_pedestal_2.surface
	for _,e in s:contents() do
		if e.go.name == "fancy_skull" then
			e.go:destroy()
			playSound("secret")
			counter_2.counter:decrement()
			ud_alcove_6.surface:addItem(spawn("fancy_skull").item)
		end
	end
end

Code: Select all

function habba()
    dm_surface_throne_1.surface:addItem(spawn("g1_treasure_golden_crown").item)
end
Screenshots included

https://ibb.co/e2K7PT
https://ibb.co/hrPcr8
Last edited by Pompidom on Tue Jul 24, 2018 9:57 pm, edited 1 time in total.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Moving item from one pedestial to the next

Post by Pompidom »

This question actually just gave me the idea to make a trophy room where you turn in mythical treasures that will be displayed on pedestals in an animation while giving you rewards :)
Torquemada
Posts: 25
Joined: Fri Apr 05, 2013 10:52 pm

Re: Moving item from one pedestial to the next

Post by Torquemada »

It's a one time only but I need to destroy all the items I placed on the pedestial before the other item is moved to it.
I don't know why I get stack overflow error.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Moving item from one pedestial to the next

Post by Pompidom »

This can be perfectly be solved with my clunky script

Take my script,
make multiple
if e.go.name == things
that decrement a counter
then when the counter has decremented x times (x for the amount of specific items) that need to be placed.

But i'm definitely interested in a more advanced script.
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Moving item from one pedestial to the next

Post by kelly1111 »

Pompidom: in your screenshot. What are those 2 round things next to the throne?
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Moving item from one pedestial to the next

Post by Pompidom »

g1_dark_temple_pedestal

They're placeholders and basically dropoff points for both skulls.

Just fix your patch and you can check out my mod yourself :D
Torquemada
Posts: 25
Joined: Fri Apr 05, 2013 10:52 pm

Re: Moving item from one pedestial to the next

Post by Torquemada »

Pompidom wrote: Tue Jul 24, 2018 10:20 pm This can be perfectly be solved with my clunky script

Take my script,
make multiple
if e.go.name == things
that decrement a counter
then when the counter has decremented x times (x for the amount of specific items) that need to be placed.

But i'm definitely interested in a more advanced script.
I think you are misunderstanding, the problem I am having is not activating the transition when correct items are placed, that I have solved, actually everything works as it should until in the final when I want to spawn the object that is on the other pedestal on the other one.
There were actually two things I wanted to know
1st. is there is better cleaner way to empty a surface like surface:emptyContents() or something like that or am I forced to use a loop and destroy each item, in that case I cannot use destroy() because that messes up the enumeration of the loop, that's why I use destroyDelayed(), although yours works because you are only destroying a single item.
2nd. why am I getting stack overflow when I spawn an item on the pedestal, doesn't happen if I do it before removing all previous items. Maybe I missed something simple.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Moving item from one pedestial to the next

Post by Pompidom »

The way I would solve it as a noob:

1st script that destroys all the items while decrementing a counter each time you have added the item.
When the counter has decremented to 0 , the counter will activate script 2, spawn the item that's displayed on pedestal 2 on pedestal 1.

2nd script simply destroys the item on pedestal 2
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Moving item from one pedestial to the next

Post by Pompidom »

Code: Select all

function surfaceDestroy(surface, item)
	for _,i in surface:contents() do
		if i.go.name == item then 
			i.go:destroy()		
			return true 
		end
	end
end

function checkHerbShop(alcove)
	if surfaceDestroy( shop_herb_alcove.surface, "blue_gem") then
		playSound("magic")
		local herb = spawn("blooddrop_cap")		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("etherweed")		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("falconskyre")		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("mudwort")		
		shop_herb_alcove.surface:addItem(herb.item)
    end
	if surfaceDestroy( shop_herb_alcove.surface, "green_gem") then
		playSound("magic")		
		local herb = spawn("blooddrop_cap")
		herb.item:setStackSize(2)
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("etherweed")
		herb.item:setStackSize(2)		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("falconskyre")		
		herb.item:setStackSize(2)
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("mudwort")
		herb.item:setStackSize(2)		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("blackmoss")		
		shop_herb_alcove.surface:addItem(herb.item)
    end
	if surfaceDestroy( shop_herb_alcove.surface, "red_gem") then
		playSound("magic")
		local herb = spawn("blooddrop_cap")
		herb.item:setStackSize(3)
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("etherweed")
		herb.item:setStackSize(3)		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("falconskyre")		
		herb.item:setStackSize(3)
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("mudwort")
		herb.item:setStackSize(3)		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("blackmoss")		
		herb.item:setStackSize(2)		
		shop_herb_alcove.surface:addItem(herb.item)
		local herb = spawn("crystal_flower")		
		shop_herb_alcove.surface:addItem(herb.item)
    end
end

This code accepts 3 different items. Taking some code from this script and combining with my script will solve your issues.
Post Reply