How to make a element conduct like BTRY?

  • coolkase
    28th May 2023 Member 0 Permalink

    I want to make a custom element that conducts like BTRY only under certain conditions (in lua), although I don't know how to do so. Is there any way to do this.

  • electroBOOM_
    21st Jun 2023 Member 0 Permalink

    BTRY doesn't conduct it only creates SPRK.

  • RebMiami
    25th Jun 2023 Member 0 Permalink

    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)

     

    Edited once by RebMiami. Last: 25th Jun 2023
  • coolkase
    26th Jun 2023 Member 1 Permalink

    Sorry I havent responded, but thanks for the help

     

    Edit: Your comments helped me a lot. My scripts have always been laggy because I never used if s ~= n then . Thank you.

    Edited once by coolkase. Last: 26th Jun 2023