More Optimized Electricity?

  • RamenNoods
    1st February Member 0 Permalink

    Does anyone know a more optimized way of generating spark? I've been using the method below and it's so laggy.

     

    for p in sim.neighbors(x, y, 2, 2) do
                if sim.partProperty(p, "life") == 0 and bit.band(elem.property(sim.partProperty(p, "type"), "Properties"), elem.TYPE_SOLID + elem.PROP_CONDUCTS) == elem.TYPE_SOLID + elem.PROP_CONDUCTS then
                    local ctype = sim.partProperty(p, "type")
                    sim.partChangeType(p, elem.DEFAULT_PT_SPRK)
                    sim.partProperty(p, "life", 4)
                    sim.partProperty(p, "ctype", ctype)
                end
    end
  • ArolaunTech
    1st February Member 0 Permalink

    I don't know why you're putting that in your update function. Just set PROP_CONDUCTS and PROP_LIFE_DEC to make the game automatically conduct sparks for you. It will also be much faster than implementing spark conduction logic in Lua.

     

    Anyway, Lua elements tend to be laggy when you're looping over neighbors like this, especially if you're looking for neighbors more than 1 pixel away. I've been able to use the surround_space and not_type arguments to the update function to my advantage to make less laggy Lua elements, but I don't think that would work here.

  • RamenNoods
    1st February Member 1 Permalink

    @ArolaunTech (View Post)

     Doesn't that just make an element conductive..? I'm trying to generate electricity like sensors or batteries.

     

     

  • creator_of_fail
    8th March Member 0 Permalink

    When you say laggy, how laggy is it? My for loops run very fast.

     

    I'm also very sorry for necroposting, I did not see the date.

    Edited once by creator_of_fail. Last: 8th March