Having two graphics.drawBox at the same time not working

  • #1, by nerdSunday, 10. February 2019, 18:08 5 years 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 2019, 18:38 5 years ago
    you are overwriting the draw function each time you call it. register a separate draw function instead.

    Imperator

    7278 Posts

  • #3, by nerdSunday, 10. February 2019, 19:03 5 years ago
    How do I do that?

    Forum Fan

    147 Posts

  • #4, by afrlmeSunday, 10. February 2019, 21:11 5 years ago
    graphics.addDrawFunc("draw2()", 0)

    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

    7278 Posts

  • #5, by nerdSunday, 10. February 2019, 21:13 5 years ago
    Thank you

    Forum Fan

    147 Posts

  • #6, by nerdTuesday, 12. February 2019, 20:30 5 years 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 2019, 20:55 5 years 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 2019, 21:25 5 years 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

    2346 Posts

  • #9, by nerdTuesday, 12. February 2019, 21:39 5 years 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 2019, 22:09 5 years 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

    2346 Posts

  • #11, by nerdTuesday, 12. February 2019, 22:21 5 years 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