Having two graphics.drawBox at the same time not working

  • #10, 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


  • #11, by afrlmeTuesday, 12. February 2019, 22:52 5 years ago
    math.floor() is used to round up numbers containing decimal values to (integers) whole numbers, so instead of something like 1.21, you would convert it to 1.

    Imperator

    7278 Posts

  • #12, by nerdWednesday, 13. February 2019, 10:26 5 years ago
    It doesn't work, the bar keeps disappearing, is the code written right?
    local health

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



    function drawHealthBar()

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

    -- + --

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

    end



    registerEventHandler("mainLoop","drawHealthBar")



    Forum Fan

    147 Posts

  • #13, by nerdWednesday, 13. February 2019, 10:38 5 years ago
    I even tried this, but it's not working
    local ragno_hp

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


    function drawRagno_hp()

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



    ragno_hp_integer = math.floor(ragno_hp)


    -- + --

    function draw4() graphics.drawBox(1027, 85, ragno_hp_integer, 40, 0x00ffff, 1) end

    end



    registerEventHandler("mainLoop","drawRagno_hp")





    Forum Fan

    147 Posts

  • #14, by afrlmeWednesday, 13. February 2019, 12:04 5 years ago
    I don't know, but like I said... you don't actually need the mainLoop events.

    local health
    
    local fireball_level
    
    
    
    function draw()
    
    
    
       health = math.floor((Values["MC_hp"].Int / 100) * 600)
    
       fireball_level = math.floor((Values["MC_fireball_level"].Int / 100) * 100)
    
    
    
       graphics.drawBox(293, 85, health, 40, 0x00ffff, 1)
    
       graphics.drawBox(1780, 669, fireball_level, 40, 0x00ffff, 1)
    
    
    
    end
    
    
    
    graphics.addDrawFunc("draw()", 0)

    I'm a bit confused as to why you are sharing the fireball_level by 100, then multiplying it by 100, wouldn't that just restore it back to the same value?

    Quick note: you can kill the draw function by using this line...

    removeDrawFunc("draw()")

    or alternatively you can also kill it by replacing the draw function content, but that means you would need to add in the code again if you wanted to use it again, as it would be a destructive method.

    function draw() end -- destructive method

    Imperator

    7278 Posts

  • #15, by nerdWednesday, 13. February 2019, 13:37 5 years ago
    It works
    local mc_health

    local ragno_hp

    local fireball_level

    local fart_level


    function draw()

    -- + -- -- + -- -- + -- -- + -- -- + -- -- + -- -- + --

    mc_health = math.floor((Values["MC_hp"].Int / 100) * 600)

    ragno_health = math.floor((Values["ragno_hp"].Int / 100) * 600)

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

    fart_level = math.floor((Values["MC_fart_level"].Int / 100) * 100)

    -- + -- -- + -- -- + -- -- + -- -- + -- -- + -- -- + --

    graphics.drawBox(293, 85, mc_health, 40, 0x00ffff, 1)

    graphics.drawBox(1027, 85, ragno_health, 40, 0x00ffff, 1)

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

    graphics.drawBox(1780, 816, fart_level, 10, 0x00ffff, 1)

    -- + -- -- + -- -- + -- -- + -- -- + -- -- + -- -- + --

    end

    graphics.addDrawFunc("draw()", 0)
    Thank you!

    Forum Fan

    147 Posts

  • #16, by afrlmeWednesday, 13. February 2019, 13:49 5 years ago
    no problem, but still you don't need the shared by 100, multiplied by 100 bit. it's returning the original value. grin

    fart_level = math.floor((Values["MC_fart_level"].Int / 100) * 100)
    to...
    fart_level = Values["MC_fart_level"].Int

    Imperator

    7278 Posts

  • #17, by nerdWednesday, 13. February 2019, 23:05 5 years ago
    I am gonna take them out

    Forum Fan

    147 Posts