TPT Lua API graphics not working

  • camtech56
    2nd Jun 2018 Member 0 Permalink

    I am trying to make a modded element in lua that creates graphics as part of its update function. However, I noticed that they don't seem to be working. I've tried different view modes and tested it in console. The table for the graphics functions exists and the functions themselves exist, but calling them seems to do nothing. Even calling them with incorrect arguments doesn't cause an error. Is the graphics library deprecated like the old Lua API or am I using the functions wrong?

  • jacob1
    2nd Jun 2018 Developer 0 Permalink
    Can you post the code you are using to do this?

    tpt.graphics_function is technically deprecated but behaves exactly like elem.property(ID, 'Graphics', func). It shouldn't matter which one you use.

    Here's an example graphics function from one of my scripts:
    local function graphics(i,colr,colg,colb)
    local life = sim.partProperty(i, sim.FIELD_LIFE)
    local divide = life == 10 and 1 or (2.5-life/8)
    return 0,1,255,colr/divide,colg/divide,colb/divide
    end
    elem.property(PBHL, "Graphics", graphics)

    Edited once by jacob1. Last: 2nd Jun 2018
  • camtech56
    3rd Jun 2018 Member 0 Permalink

    I was talking about the graphics.* or gfx.* functions. In particular, I wanted to use the gfx.fillCircle() function; however, I called it both in an update function and in the console and yet it did not appear nor return anything. It doesn't even return nil.

  • jacob1
    3rd Jun 2018 Developer 0 Permalink
    Those functions only draw stuff for one frame. You need to make sure to draw the same thing every frame so that the user can see it.

    I'm unsure if the gfx.* functions work inside of graphics functions, which is really annoying. They do work inside tick functions though (tpt.registers_step)