Create particle every 2 secs help?

  • QuentinADay
    5th Dec 2014 Member 0 Permalink

    Can Somebody help me make a function that make URAN produce a particle(ex.PROT) every 2 seconds? I can't figure out how(if its even possible) 

  • Klus
    5th Dec 2014 Member 0 Permalink

    I was going to say 'no.' but then I didn't when I realised that if I did it would make way too much sense.

  • Lord_Bowserinator
    5th Dec 2014 Member 0 Permalink

    Just make a variable and if variable%120==0 then make prot

    (My lua is bad thats persuocode) (It's 120 since the fps is 60 I'm not sure get jacob1)

     

    Edited once by Lord_Bowserinator. Last: 5th Dec 2014
  • zBuilder
    6th Dec 2014 Member 0 Permalink

    I made something,but it might not be what you mean. it releases a steady amount, but keeps the numbers emitted down so that it's not flooding the screen.

    http://pastebin.com/2ziEE0iD

     

    or did you mean every 2 seconds every particle would release one?

  • FeynmanLogomaker
    6th Dec 2014 Member 0 Permalink

    Even better, you could use the os.clock() function to get how many seconds have elapsed.

     

    Actually, now that I think about it, that's maybe not as good an idea, then it would behave differently for different users. It would still be a good idea to add a little randomization, maybe:

     

    local frame, lapse = 0, 120
    function uran_update_function(i, x, y, s, n)
        frame = frame + 1
        if frame % lapse == 0 then
            make_a_particle(stuff, x + math.random(-2,2), y + math.random(-2,2))
            lapse = math.floor(math.random(60, 180))
        end
    end

  • jward212
    6th Dec 2014 Member 0 Permalink

    Feynman YA beat me, the only other way is to base it of frame rate(in witch I should have read the previous comments before posting :P)

    Edited once by jward212. Last: 6th Dec 2014
  • zBuilder
    6th Dec 2014 Member 0 Permalink

    FeynmanLogomaker:

    Even better, you could use the os.clock() function to get how many seconds have elapsed.

     

    Actually, now that I think about it, that's maybe not as good an idea, then it would behave differently for different users. It would still be a good idea to add a little randomization, maybe:

     

    local frame, lapse = 0, 120
    function uran_update_function(i, x, y, s, n)
        frame = frame + 1
        if frame % lapse == 0 then
            make_a_particle(stuff, x + math.random(-2,2), y + math.random(-2,2))
            lapse = math.floor(math.random(60, 180))
        end
    end

     seems to be similar but cleaner- though depending on what particle you emit(prot,for example), there will be a LOT of that particle on screen

  • boxmein
    6th Dec 2014 Former Staff 0 Permalink
    @FeynmanLogomaker (View Post)
    I suppose it's better off to make this reaction frame-based as well, since the entirety of TPT operates on frames, however in other cases I'd use your time-based method to accomplish this.
  • zBuilder
    6th Dec 2014 Member 0 Permalink

    boxmein:

    @FeynmanLogomaker (View Post)
    I suppose it's better off to make this reaction frame-based as well, since the entirety of TPT operates on frames, however in other cases I'd use your time-based method to accomplish this.

     

    how do you get frame btw?

  • boxmein
    6th Dec 2014 Former Staff 2 Permalink
    @zBuilder (View Post)
    Frames, also called ticks/steps, are really easy to use as timing for an element:

    local frame = 0
    tpt.register_step(function()
    if frame == 60
    frame = 0
    -- do stuff here, will happen every 60 frames
    end
    frame = frame + 1
    end)