Page 1 of 1

remove items from surfaces via script

Posted: Sun Aug 02, 2015 4:40 pm
by Granamir
HI everyone,
i'm trying to build a food dispencer so i thought it would destroy any food inside of it when i activate it, but i'm having trouble if already are items in alcove.
Plus i read somewhere that i can have save problems destroying items in alcove.
So anyone has any solution or tips i can follow?
TY

my script so far is:

Code: Select all

function dispensingFood()
	for _, i in castle_alcove_1.surface:contents() do
		if i.go.usableitem:getNutritionValue() ~= nil then 
		print (i.go.id)
		i.go:destroy() end
	end
	local foods = {"snail_slice","herder_cap","pitroot_bread","rat_shank","rat_swarm_shank","boiled_beetle","baked_maggot","ice_lizard_steak","mole_jerky","blueberry_pie","cheese","bread","sausage","turtle_steak","smoked_bass","silver_roach","turtle_eggs","horned_fruit","warg_meat","fjeld_warg_meat","lizard_stick","snake_tail","toad_tongue","borra"}
	local food = math.random(1,24)
	castle_alcove_1.surface:addItem(spawn(foods[food]).item)
end