graphics.drawText is not working

  • resucits555
    15th May Member 0 Permalink

    I want to get started with lua programming and wrote a simple program:

    graphics.drawText(50,50, "Hello")

    and it just doesn't work! Nothing appears on the screen.

     

    Would appreciate any help!

  • Cracker1000
    15th May Member 1 Permalink

    @resucits555 (View Post)

     It works but the problem is it will show up for just one frame. You will have to register a function which shows it for multiple frames so that you can actually view it.

     

    Something like the code sample I am providing below.

     

    Local function drawtextgraphics()

    gfx.drawText(50,50,"Hello world")

    end

    Event.register(event.tick,drawtextgraphics())

     

    Note that I haven't tested the code but it should work just fine :)

  • resucits555
    15th May Member 0 Permalink

    @Cracker1000 (View Post)

     Thank you but the code isn't working. I've tried to find the problem (I have some experience with lua) but haven't found it

  • jacob1
    15th May Developer 1 Permalink
    There's a mistake in the evt.register function, drawtextgraphics is called as a function when it should just be passed in as a function argument. There's also some typos due to autocorrect. Here's the fixed version:

    local function drawtextgraphics()
    gfx.drawText(50, 50, "Hello world")
    end
    evt.register(evt.tick, drawtextgraphics)
    Edited 2 times by jacob1. Last: 15th May
  • resucits555
    15th May Member 0 Permalink

    @jacob1 (View Post)

     Thank you! I don't know how I missed that