Bacteria is self-destructing

  • 0xHenryMC
    1st July Member 0 Permalink

    Im making a bacteria and including it into my Fun n' Chemicals script, but something happend.

    My bacteria spread but it die even when nothing is touching it.

     

    While getting your answer, i'll put my script inactive for some days.

    code

  • Jerehmia
    3rd July Member 0 Permalink

    Firstly you shouldn't mix the old tpt.* and the new lua interface, try not to use the tpt.* stuff.

     

    In your script you first pick a random location anywhere in the 3x3 square surrounding the starting particle, including the location of the starting particle itself (math.random(-1,1) could generate a 0 twice). Then you decrease the life of the starting particle by one if there is a particle at the random location that has the DEADLY propery set.

     

    I suspect that your BTRA has the DEADLY property set and since there is a 1:9 chance that the random location picked will be the location of the BTRA particle itself, there is a 1:9 chance that a BTRA's life will be decremented every frame because it "sees" its own deadlyness. Because a BTRA's life value starts at 100 it would take 900 frames on average for a single BTRA (not surrounded by anything) to die because of its own deadlyness. Would that be right?

    Edited once by Jerehmia. Last: 3rd July
  • 0xHenryMC
    3rd July Member 0 Permalink

    Holy, yes, my bacteria was deadly. Thanks

    P/S: I forgot to append "~= 0" after bit.band(...) so i think it is defined and considered valid.

    Edited once by 0xHenryMC. Last: 3rd July
  • Jerehmia
    3rd July Member 0 Permalink

    The TPT console is a fully functional Lua interpreter, so you can test your Lua expressions by entering them in the console.

     

    If you want to keep your BTRA deadly you can simply skip the decrement if the random location is equal to the starting location, just add and (thatx ~= x or thaty ~= y) to the first if statement.

    Edited 2 times by Jerehmia. Last: 3rd July
  • 0xHenryMC
    4th July Member 0 Permalink

    ohh

    sure

    but what about colliding with other BTRAs?

  • Jerehmia
    4th July Member 0 Permalink

    You could ignore all neighboring particles of type BTRA, instead of the above condition add and nearby ~= btra to the first if statement

  • 0xHenryMC
    5th July Member 0 Permalink

    thanks