Page 1 of 1

hud_remove problem [SOLVED]

PostPosted: Wed Jun 15, 2016 15:14
by azekill_DIABLO
Image

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local hud_blodd = {}

minetest.register_on_player_hpchange(function(player, hp_change)
   if hp_change<0 then
      player:hud_add({
         hud_elem_type = "image",
         id = 1,
         position = {x = 0.5, y = 0.5},
         scale = {
         x = -100,
         y = -100
      },
      text = "blood_splash.png"
   })
   
minetest.after(0.8, function(player, hp_change)
      player:hud_remove({
         hud_elem_type = "image",
         id = 1,
         position = {x = 0.5, y = 0.5},
         scale = {
         x = -100,
         y = -100
      },
      text = "blood_splash.png"
   })
end
)
   end
end
)



i have wierd problem with this... it says "player is a nil value"
Please help me!

Re: hud_remove problem

PostPosted: Wed Jun 15, 2016 15:28
by Naj
I guess you should pass arguments needed by your callback function to minetest.after.


Minetest Dev Wiki says :
Parameters for minetest.after :
1: Time that has to pass for the function to be ran
2: Function
3: Optional - parameters to the function, use a list for multiple

So it should be something like :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.after(0.8, function(player, hp_change)
      player:hud_remove({
...
end,
(player, hp_change)
)
   end
end
)

Re: hud_remove problem

PostPosted: Wed Jun 15, 2016 15:34
by azekill_DIABLO
ok thx will try that now!!!

Re: hud_remove problem

PostPosted: Wed Jun 15, 2016 15:37
by rubenwardy
hud_remove takes an id.

local id = player:hud_add({ })
player:hud_remove(id)

Re: hud_remove problem

PostPosted: Wed Jun 15, 2016 15:38
by azekill_DIABLO
ok thx

@naj does not work says there { missing or something

Re: hud_remove problem

PostPosted: Wed Jun 15, 2016 15:43
by rubenwardy
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local hud_blodd = {}

minetest.register_on_player_hpchange(function(player, hp_change)
    if hp_change<0 then
        local id = player:hud_add({
            hud_elem_type = "image",
            id = 1,
            position = {x = 0.5, y = 0.5},
            scale = {
                x = -100,
                y = -100
            },
            text = "blood_splash.png"
        })

        minetest.after(0.8, function(name, id)
            local player = minetest.get_player_by_name(name)
            if player then
                player:hud_remove(id)
            else
                -- player has left the game
            end
        end, player:get_player_name(), id)
    end
end)


You really should work on your code style, it makes it easier to read and to help you.
You need to do player:get_player_name then get_player_by_name as it is possible that the player leaves the game in that 0.8. You should never store player objects and access them on another callback.

Re: hud_remove problem

PostPosted: Wed Jun 15, 2016 15:49
by azekill_DIABLO
ok thank you!
and sorry for my code i'm doing my best but i just done a copy and paste from another editor...

Re: hud_remove problem

PostPosted: Wed Jun 15, 2016 15:56
by azekill_DIABLO
Thank @all people for this fast help!
the problem has been solved! :)
Image