How do I print to screen?

  • Videogamer555
    5th Dec 2017 Member 0 Permalink
    Is there a way to print text to screen, such as a simple "Hello World" program? I can't find anything in the TPT Lua reference here https://powdertoy.co.uk/Wiki/W/Lua.html
  • LBPHacker
    5th Dec 2017 Developer 0 Permalink

    gfx.drawText is the most up-to-date API that draws to the screen. The screen is redrawn in every tick though, so you have to call it every tick one way or another. Doing it in a function that you later register as a step handler is what makes the most sense.

     

    tpt.register_step(function()
        gfx.drawText(100, 100, "Hello World!")
    end)

  • jacob2
    5th Dec 2017 Member 0 Permalink
    Or for one time messages, just use tpt.log
  • Videogamer555
    5th Dec 2017 Member 0 Permalink

    LBPHacker:

    gfx.drawText is the most up-to-date API that draws to the screen. The screen is redrawn in every tick though, so you have to call it every tick one way or another. Doing it in a function that you later register as a step handler is what makes the most sense.


     


    tpt.register_step(function()
        gfx.drawText(100, 100, "Hello World!")
    end)



    Just searched the TPT Lua wiki here https://powdertoy.co.uk/Wiki/W/Lua.html and didn't find anything about "gfx" because all of the functions were labeled starting with "tpt". The closest function I found was tpt.drawtext (notice also how there's also no capital T, it's all lowercase).

    What I really need is a way to draw text that stays on the screen until either a certain amount of time passes (like when you hover over an element name in the tool box), or until you click the screen (like the startup text that appears whenever you start Powder.exe, such as the version number and the little bit of help info).

    If there are in fact new Lua functions in TPT, then probably these should be added to the wiki.
  • jacob2
    5th Dec 2017 Member 0 Permalink
    @Videogamer555 (View Post)
    Use this page instead: https://powdertoy.co.uk/Wiki/W/Powder_Toy_Lua_API.html

    You'll have to have a counter, and stop drawing the text when the counter gets to 0. Maybe later I can provide an example if you haven't figured it out by then.