Page 1 of 1

stack overflow

Posted: Wed Jul 13, 2016 2:44 pm
by vieuxchat
Here is my code

Code: Select all

function elementAjoute()	
	local dagger_id

	hudPrint(beacon_furnace_2.id)
	dagger_id = trouveUneDague(beacon_furnace_2.surface)
	
	local e = findEntity(dagger_id)
	if e ~= nil then 
		hudPrint(e.name) 
		local s = spawn("ethereal_blade", party.level, beacon_furnace_2.x, beacon_furnace_2.y, beacon_furnace_2.facing, beacon_furnace_2.elevation)
		--beacon_furnace_2.surface:addItem(s.item) -- That line is causing me trouble
		e:destroyDelayed()
	end
	
end

function trouveUneDague(surface)
	for v,i in surface:contents() do
		hudPrint(i.go.id)
		if i.go.name == "dagger" then return i.go.id end
	end
	return "nil"
end
Why do I get a stack overflow at the line "beacon_furnace_2.surface:addItem(s.item)" ?

Re: stack overflow

Posted: Wed Jul 13, 2016 3:12 pm
by Dr.Disaster
AFAIK addItem() works with containers, monsters, sockets and surfaces and the syntax tells you want to use the surface part.

Yet in the code it seems you picked an item ("dagger") as the surface you want to add something to.

Re: stack overflow

Posted: Wed Jul 13, 2016 3:47 pm
by vieuxchat
I don't think so, the name "beacon_furnace_2.surface" means that the surface is owned by the beacon furnace.

Re: stack overflow

Posted: Wed Jul 13, 2016 7:36 pm
by minmay
You get a stack overflow because you have a connector from the surface to elementAjoute(). So when you add an item to the surface inside elementAjoute(), it causes a recursive call to elementAjoute(), which adds another item to the surface, which causes another recursive call to elementAjoute(), which adds another item to the surface...

Re: stack overflow

Posted: Wed Jul 13, 2016 7:53 pm
by vieuxchat
I'm stupid.
You're right.

Thank you.