Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Having two graphics.drawBox at the same time not working

  • #1, di nerd horas 7 years ago Zitieren

    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")


  • #2, di afrlme horas 7 years ago Zitieren
    you are overwriting the draw function each time you call it. register a separate draw function instead.
  • #3, di nerd horas 7 years ago Zitieren
    How do I do that?
  • #4, di afrlme horas 7 years ago Zitieren
    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.
  • #5, di nerd horas 7 years ago Zitieren
    Thank you
  • #6, di nerd horas 7 years ago Zitieren
    Is there a way to determine the "z" position of the drawboxes between interface objects?
  • #7, di nerd horas 7 years ago Zitieren
    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
  • #8, di sebastian horas 7 years ago Zitieren
    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.

  • #9, di nerd horas 7 years ago Zitieren
    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"?
  • #10, di sebastian horas 7 years ago Zitieren
    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) 
  • #11, di nerd horas 7 years ago Zitieren
    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")