BTRY doesn't conduct it only creates SPRK.
Using sim.partCreate(-1, x, y, elem.DEFAULT_PT_SPRK) will spark the particle at x, y if it's a conductor. You can make a custom Lua element act like a battery by doing this to all of the particle's neighbors like this:-- Run through all particles in a 3x3 square around this one
for dx = -1, 1 do
for dy = -1, 1 do
sim.partCreate(-1, x + dx, y + dy, elem.DEFAULT_PT_SPRK)
end
end
Here's a small script I made as a demonstration. It adds HBTY, or Heat Battery, which only produces electricity when heated above 100°C.
local hbty = elem.allocate("EXAMPLE", "HBTY")
-- Note that copying properties from BTRY has no effect creating electricity.
-- This only copies properties listed on https://powdertoy.co.uk/Wiki/W/Element_Properties.html
elem.element(hbty, elem.element(elem.DEFAULT_PT_BTRY))
elem.property(hbty, "Name", "HBTY")
elem.property(hbty, "Description", "Heat battery. Produces electricity when heated above 100C.")
elem.property(hbty, "Colour", 0xFA543E)
elem.property(hbty, "Update", function(i, x, y, s, n)
-- Important optimization; prevents HBTY particles that aren't touching any non-HBTY particles from running their code.
-- s is the number of empty spaces in the 3x3 square around the particle
-- n is the number of non-HBTY particles in the 3x3 square around the particle
if s ~= n then
-- Get the particle's temp, adjusted to celsius
local temp = sim.partProperty(i, "temp") - 273.15
if temp > 100 then
-- Run through all particles in a 3x3 square around this one
for dx = -1, 1 do
for dy = -1, 1 do
if dx ~= 0 or dy ~= 0 then
-- Don't try to conduct to the heat battery itself
sim.partCreate(-1, x + dx, y + dy, elem.DEFAULT_PT_SPRK)
end
end
end
end
end
end)