Why is this so laggy?

  • TPT_PL
    3rd Sep 2016 Member 1 Permalink
    Hi.
    I want to make an acidic pack for my Lua script, Big Dig Science. (If you do not understand what "pack", just click the link.)
    But the elements I made are very laggy. Why?
  • LBPHacker
    3rd Sep 2016 Developer 0 Permalink

    I don't think it's the elements' fault. I've reduced them to static elements with only a description and no update function and they're just as laggy as before. I think it's due to the simple fact that they're Lua elements, even though I see no reason for them to be laggy if no Lua-side update function is called.

  • TPT_PL
    3rd Sep 2016 Member 1 Permalink
    But guy. I did a Particle Pack (see the link in the first post) and theyre not laggy even with an Update function. Something's going up.
  • LBPHacker
    3rd Sep 2016 Developer 0 Permalink

    So let me get this straight. The link in the first post (which I've visited, thank you) redirects me to a list of packs of which only one is ready at the moment, and that is not the one you're having problems with, as you've stated in the second post. You have shown us no other piece of code besides that. This means you're asking about code you haven't shown us yet. As my crappy HP printer likes to say, "user interaction required".

  • jacob1
    3rd Sep 2016 Developer 0 Permalink
    Yes, if you can post the laggy code i'll look at it :P (or someone else will)
  • TPT_PL
    4th Sep 2016 Member 1 Permalink
    I can't believe I'm so stupid.
    This is a website for me.
    Oh, and this is a website for you.
    Edited once by TPT_PL. Last: 4th Sep 2016
  • LBPHacker
    4th Sep 2016 Developer 0 Permalink

    I assume elem.DEFAULT_PT_OXYG is the missing constant on line 14.

  • TPT_PL
    4th Sep 2016 Member 1 Permalink
    Thank you. As I said, I am an idiot.
    But it's still #aslaggyasidonteven
  • LBPHacker
    4th Sep 2016 Developer 0 Permalink

    I don't think there's anything in there that should make this laggy besides, well, this being Lua and all.

     

    Well, the first thing I found is that the else branch in H2SO4's update function is quite the performance hit. I moved the .type ~= H2SO4 check to the front and it's way faster now.

     

    The funny thing is, it's a bit faster if I implement sim.neighbours right there in the function with two inline for loops and a call to partID.

    Edited 2 times by LBPHacker. Last: 4th Sep 2016
  • ssccsscc
    4th Sep 2016 Member 1 Permalink

    Try replace

    for r in sim.neighbors(x, y, 1, 1) do

    to
    r = sim.partID(x+math.random(-1,1),y+math.random(-1,1))
    if r~= nil then