Issues with making element explode.

  • coolkase
    11th Jun 2023 Member 0 Permalink

    Im trying to make one of my elements explode like SNOW(SING). Heres my code:

     

            local eparticles = {elements.DEFAULT_PT_NEUT, elements.DEFAULT_PT_PROT, elements.DEFAULT_PT_ELEC}

            local xx = -2
            local yy = -2
            while yy < 2 do
              while xx < 2 do
                sim.partCreate(i, x+xx, y+yy, eparticles[math.random(1,3)])
                xx = xx + 1
              end
              yy = yy + 1
            end

     

    I thought it would make a 5x5 square around the particle made of a random energy particle but it only makes one energy particle from the original particle. Does anyone know what I did wrong?

  • RebMiami
    12th Jun 2023 Member 0 Permalink

    There's two issues here:

    1. You're passing the bomb particle's ID (i) into the first argument of sim.partCreate, which means that the radiation particle will delete each previous one when it's place. Try using -1 instead
    2. You aren't resetting the value of xx after the inner loop finishes, which means that only one row of particles will appear if you fixed the above issue. Try setting xx back to -2 after the inner loop finishes
    Edited once by RebMiami. Last: 12th Jun 2023
  • coolkase
    12th Jun 2023 Member 1 Permalink

    @RebMiami (View Post)

     oh ok ill try that, i dont know how i didnt notice i wasnt resetting xx

     

     thank you. ill still need to to a bit of tinkering to stop the hydrogen fusion but it bursts how i want it:

     

    burst of protons, photons, electrons, and neutrons.

    Edited 4 times by coolkase. Last: 12th Jun 2023