Page 2 of 2

Re: scripting help

Posted: Tue Jan 21, 2020 11:57 pm
by ratman
I also tried in a new project and same warning

Re: scripting help

Posted: Wed Jan 22, 2020 12:34 am
by Isaac
That's very peculiar that I don't get an error with mine, but yours does.

Okay, try this variation on the script:

Code: Select all

altar_1.surface:addConnector('onAcceptItem', self.go.id, "itemSwap")
function itemSwap(surface, item)
	local checkItem = "rock"
	local itemReplacement = "figure_skeleton"
		if item.go.item:getStackSize() == 1 and
			item.go.name == checkItem then
			item.go:destroyDelayed()
			surface:addItem(spawn(itemReplacement).item)
			--optional effect 
			surface.go:createComponent('Particle'):setParticleSystem('beacon_crystal')
			surface.go.particle:setDestroySelf(true)
			surface.go.particle:fadeOut(1)
			surface.go:playSound('teleport')
			return false
		end
end
This one gives me no errors, but handles things slightly different than before; based on a hunch. The original script did have a bug—though it didn't crash for me. This version fixes that bug.

Re: scripting help

Posted: Wed Jan 22, 2020 12:50 am
by ratman
that works thank you. :D

Re: scripting help

Posted: Tue Feb 18, 2020 5:17 pm
by billb52
Hi Issac
Tried using your variation of the script but when you place the rock on the altar I end up with 2 'skeleton figurines' every time
and the particle system does not fade out, any ideas?

Re: scripting help

Posted: Sun Nov 15, 2020 5:51 pm
by ratman
I am trying to use this but instead the player puts some items on a pedestal then hits a button which checks for items and spawns them on the pedastel

Re: scripting help

Posted: Mon Nov 16, 2020 2:08 am
by Zo Kath Ra
ratman wrote: Sun Nov 15, 2020 5:51 pm I am trying to use this but instead the player puts some items on a pedestal then hits a button which checks for items and spawns them on the pedastel
IIRC you wanted a script that turns multiple items into a single new item, like crafting potions.

Code: Select all

function transformItems(button)
	local input_item_names = { rock = false, branch = false }
	local output_item_name = "cudgel"
	local surface
	
	local alcove = findEntity("dungeon_alcove_1")
	if alcove and alcove.surface then
		surface = alcove.surface
	else
		print("Entity doesn't exist or has no surface component: dungeon_alcove_1")
		return
	end
	
	-- If any of the input items is on the surface, mark it as present in input_item_names
	for _, item in surface:contents() do
		if input_item_names[item.go.name] ~= nil then
			input_item_names[item.go.name] = true
		end
	end
	
	-- If at least one input item is missing from the surface, exit the function
	for _, present in pairs(input_item_names) do
		if present == false then
			return
		end
	end
	
	-- Destroy the input items
	for _, item in surface:contents() do
		if input_item_names[item.go.name] == true then
			-- Mark the item as destroyed in input_item_names
			-- So only one instance of the input item gets destroyed
			input_item_names[item.go.name] = false
			item.go:destroyDelayed()
		end
	end
	
	-- Add the output item to the surface
	surface:addItem(spawn(output_item_name).item)
	playSound("secret")
	hudPrint("The alcove has created a new " .. output_item_name .. ".")
end

Re: scripting help

Posted: Mon Nov 16, 2020 3:20 am
by ratman
Thanks. How would I make it so it destroys the items even if they are not the right ones?