Having two graphics.drawBox at the same time not working

  • #1, by nerdSunday, 10. February, 18:08 7 months ago

    I got an health bar and a special move energy bar. Two "graphics.drawBox", both work if taken alone, but once they are in sequence only the last one executes.
    How do I get them work in parallel?

    First "graphics.drawBox" script:




    local health

    graphics.addDrawFunc("draw()", 0)



    function drawHealthBar()

    health = (Values["MC_health"].Int / 100) * 600

    -- + --

    function draw() graphics.drawBox(293, 85, health, 40, 0x00ffff, 1) end

    end



    registerEventHandler("mainLoop", "drawHealthBar")


    Second "graphics.drawBox" script:
    local fireball_level

    graphics.addDrawFunc("draw()", 0)



    function drawFireballBar()

    fireball_level = (Values["MC_fireball_level"].Int / 100) * 100

    -- + --

    function draw() graphics.drawBox(1780, 669, fireball_level, 40, 0x00ffff, 1) end

    end



    registerEventHandler("mainLoop", "drawFireballBar")


    Forum Fan

    147 Posts


  • #2, by AFRLmeSunday, 10. February, 18:38 7 months ago
    you are overwriting the draw function each time you call it. register a separate draw function instead.

    Imperator

    6587 Posts

  • #3, by nerdSunday, 10. February, 19:03 7 months ago
    How do I do that?

    Forum Fan

    147 Posts

  • #4, by AFRLmeSunday, 10. February, 21:11 7 months ago
    graphics.addDrawFunc("draw2()", 0)
    1

    now wrap the second one in draw2() instead of draw().

    quick note: technically you could do it all inside of the draw() function as the draw function is also a loop, so you don't actually need to use mainLoop.

    Imperator

    6587 Posts

  • #5, by nerdSunday, 10. February, 21:13 7 months ago
    Thank you

    Forum Fan

    147 Posts

  • #6, by nerdTuesday, 12. February, 20:30 6 months ago
    Is there a way to determine the "z" position of the drawboxes between interface objects?

    Forum Fan

    147 Posts

  • #7, by nerdTuesday, 12. February, 20:55 6 months ago
    I've also noticed that when the player "health points" go down to 82/100, 57/100 or 34/100 the drawBox bar basically disappears

    Forum Fan

    147 Posts

  • #8, by sebastianTuesday, 12. February, 21:25 6 months ago
    Is there a way to determine the "z" position of the drawboxes between interface objects?
    first function call, first drawn. Nothing really to do here. If you need to draw it in other orders, you may first calculatte/define all parameters and then use these in a specific function to determine which gets drawn first.

    Thread Captain

    2318 Posts

  • #9, by nerdTuesday, 12. February, 21:39 6 months ago
    The drawBox bar disappears when the character health points go down to 82, 57, 34.
    Is it because those numbers are incompatible with this equation "health = (Values["MC_health"].Int / 100) * 600"?

    Forum Fan

    147 Posts

  • #10, by sebastianTuesday, 12. February, 22:09 6 months ago
    The drawBox bar disappears when the character health points go down to 82, 57, 34.
    Is it because those numbers are incompatible with this equation "health = (Values["MC_health"].Int / 100) * 600"?

    possible. you could do math.floor(Values["MC_health"].Int / 100) * 600) 

    Thread Captain

    2318 Posts

  • #11, by nerdTuesday, 12. February, 22:21 6 months ago
    The script is gonna look like this? (I've no programming background)

    graphics.addDrawFunc("draw()", 0)

    function drawHealthBar()

    health = math.floor(Values["MC_health"].Int / 100) * 600

    -- + --

    function draw() graphics.drawBox(293, 85, health, 40, 0x00ffff, 1) end

    end
    registerEventHandler("mainLoop", "drawHealthBar")

    Forum Fan

    147 Posts

Write post