hud_remove problem [SOLVED]

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

hud_remove problem [SOLVED]

by azekill_DIABLO » Wed Jun 15, 2016 15:14

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!
Last edited by azekill_DIABLO on Wed Jun 15, 2016 15:56, edited 2 times in total.
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
Naj
Member
 
Posts: 170
Joined: Sat Sep 19, 2015 21:14
GitHub: pyrollo
In-game: naj

Re: hud_remove problem

by Naj » Wed Jun 15, 2016 15:28

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
)
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: hud_remove problem

by azekill_DIABLO » Wed Jun 15, 2016 15:34

ok thx will try that now!!!
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: hud_remove problem

by rubenwardy » Wed Jun 15, 2016 15:37

hud_remove takes an id.

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

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: hud_remove problem

by azekill_DIABLO » Wed Jun 15, 2016 15:38

ok thx

@naj does not work says there { missing or something
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: hud_remove problem

by rubenwardy » Wed Jun 15, 2016 15:43

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.
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: hud_remove problem

by azekill_DIABLO » Wed Jun 15, 2016 15:49

ok thank you!
and sorry for my code i'm doing my best but i just done a copy and paste from another editor...
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: hud_remove problem

by azekill_DIABLO » Wed Jun 15, 2016 15:56

Thank @all people for this fast help!
the problem has been solved! :)
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 15 guests

cron