Flashbang isn't flashing...

  • 0xHenryMC
    27th June Member 0 Permalink

    Im trying to make a flashbang with this code...

     

    elem.property(fb, "Update", function (i,x,y,s,n)
    -- Element logics not included

    graphics.fillRect(5,5,graphics.WIDTH, graphics.HEIGHT)
    sim.partProperty(i, "life", sim.partProperty(i, "life") - 1)
    if sim.partProperty(i, "life") ~= nil and sim.partProperty(i, "life") == 0 then sim.partKill(i); end
    end)

     

    No matter how i change the code (Even, i tried to use the legacy tpt. API), it will ONLY flash white when i use an (tick) event hook. But also, when i try to unhook that event, it will keep going... Help!

  • creator_of_fail
    27th June Member 0 Permalink

    What if you combine the two and register the tick event when created, and then unregister the tick event when life goes to 0? (I didn't test this, my screen went white after I used the tick event hook)

  • jacob1
    27th June Developer 1 Permalink
    Graphics aren't really meant to run from update functions. Try doing it in another event, like evt.beforesimdraw or evt.tick.

    You can also draw graphics from "Graphics" functions instead of "Update". In this case though, I don't think that's appropriate, since the flashbang is global, like EMP. That is drawn elsewhere in the code, esentially around where beforesimdraw would be, and is drawn just once whenever any EMP tells the sim to do that.

    Edit: Also don't use the legacy API when any new api is available. About 90% of the legacy API was removed in 98.0 and it's only working via a compatibility script. It just redirects you to the newer APIs behind the scenes.
    Edited once by jacob1. Last: 27th June
  • 0xHenryMC
    27th June Member 0 Permalink

    It's (partially) working now. Thanks