Need help with recycled element script

  • NDR149
    7th Sep 2016 Member 0 Permalink

    Trying to quickly redesign this:

    http://tpt.io/.275692

    So that it creates a new element instead of modding the original. Here's what I've got:

     

    local ktan = elements.allocate('MOD', 'KTAN')
    elements.element(elements.MOD_PT_KTAN, elements.element(elements.DEFAULT_PT_TTAN))
    elements.property(elements.MOD_PT_KTAN, "HeatConduct" , 0)
    elements.property(elements.MOD_PT_KTAN, "Hardness" , 0)
    elements.property(elements.MOD_PT_KTAN, "Weight" , 10000)
    sim.can_move(elements.DEFAULT_PT_DEST, elements.MOD_PT_KTAN, 0)
    function ttan1(i,x,y,s,n)
    local type = tpt.get_property("temp", x, y)
    if type > 300 then
    tpt.set_property("temp", -math.huge, x, y)
    end
    tpt.set_property("temp", -math.huge, x, y)
    local type = tpt.get_property("type", x + math.random(-3,3), y + math.random(-3,3))
    if type == tpt.el.dest.id then
    sim.gravMap(x/4, y/4, -256)
    end
    local type = tpt.get_property("type", x + math.random(-1,1), y + math.random(-1,1))
    if type == tpt.el.virs.id or type == tpt.el.vrss.id or type == tpt.el.vrsg.id then
    tpt.create(x + math.random(-1,1), y + math.random(-1,1), 'soap')
    end
    local rx,ry = x + math.random(-1,1), y + math.random(-1,1)
    local type = tpt.get_property("type", rx, ry)
    if type == tpt.el.soap.id then
    tpt.delete(rx, ry)
    end
    end
    tpt.element_func(ttan1,tpt.el.ktan.id)

     

    Any nasty surprises in store, or will this work fine?

  • jombo23
    7th Sep 2016 Member 0 Permalink

    try it?

  • NDR149
    7th Sep 2016 Member 0 Permalink

    Hmm. There's a few problems. The last line calls an invalid field, and both KTAN and TTAN look identical in the menu

  • LBPHacker
    7th Sep 2016 Developer 0 Permalink

    The field in the last line is invalid because tpt.el.* is (afaik) populated only by the built-in elements and no others. You should use ktan (or elements.MOD_PT_KTAN) instead of tpt.el.ktan.id, as, well, that's KTAN's ID. The other is not a nasty surprise at all. Since you copy the properties of TTAN on line 2, KTAN's description and colour will be the same as TTAN unless you change it.

    Edited 2 times by LBPHacker. Last: 7th Sep 2016
  • NDR149
    7th Sep 2016 Member 0 Permalink

    I kinda guessed the second part, but the id thing was weird for me, thanks!