License from €75 Log in
DE EN FR ES IT CZ

Having two graphics.drawBox at the same time not working

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 8 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")


    • Image in post
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 8 years ago
    you are overwriting the draw function each time you call it. register a separate draw function instead.
  4. · 8 years ago
    How do I do that?
  5. · 8 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.
  6. · 8 years ago
    Thank you
  7. · 8 years ago
    Is there a way to determine the "z" position of the drawboxes between interface objects?
  8. · 8 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
  9. · 8 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.

  10. · 8 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"?
  11. · 8 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) 
  12. · 8 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")

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?