hud.remove does not work
-
- Member
- Posts: 324
- Joined: Sun Jun 16, 2019 20:17
- Location: x=123, y=120, z=534
hud.remove does not work
I'm adding a HUD feature to a mod. For some reason, I can add a HUD but I cannot remove it. "player.hud_remove(new_hud)" (example) is completely ignored by the program (it does not even give an error message if the ID variable is not declared).
Last edited by Red_King_Cyclops on Wed Aug 21, 2019 23:48, edited 1 time in total.
Currently working on new mods.
- Pyrollo
- Developer
- Posts: 385
- Joined: Mon Jan 08, 2018 15:14
- GitHub: pyrollo
- In-game: Naj
- Location: Paris
Re: hud.remove does not work
You have to keep the ID given by player.hud_add and pass it to player.hud_remove as argument.
Please, refer to Rubenwardy's modding book, it's full of examples : https://rubenwardy.com/minetest_modding ... s/hud.html
Please, refer to Rubenwardy's modding book, it's full of examples : https://rubenwardy.com/minetest_modding ... s/hud.html
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]
-
- Member
- Posts: 324
- Joined: Sun Jun 16, 2019 20:17
- Location: x=123, y=120, z=534
Re: hud.remove does not work
I tried that. I found about hud.remove in Rubenwardy's modding book.Pyrollo wrote:You have to keep the ID given by player.hud_add and pass it to player.hud_remove as argument.
Please, refer to Rubenwardy's modding book, it's full of examples : https://rubenwardy.com/minetest_modding ... s/hud.html
Currently working on new mods.
- Pyrollo
- Developer
- Posts: 385
- Joined: Mon Jan 08, 2018 15:14
- GitHub: pyrollo
- In-game: Naj
- Location: Paris
Re: hud.remove does not work
Have you checked that your stored ID is still the good one ?
EDIT: Maybe, post some code
EDIT: Maybe, post some code
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]
Re: hud.remove does not work
player.hud_remove(handle) won't work since the player has to be passed as argument by using a colon instead of a dot like this player:hud_remove(handle). But that's not the problem here since it would cause an error. Are you sure the relevant code runs? You can verify this using minetest.log. Posting your code here might also help us find the error.
-
- Member
- Posts: 324
- Joined: Sun Jun 16, 2019 20:17
- Location: x=123, y=120, z=534
Re: hud.remove does not work
I'm using version 5.0.1. My code looks like this:
Notice that this code is very WIP.
Code: Select all
local fuel_display = clicker:hud_add({
hud_elem_type = "text",
position = {x = 0.5, y = 0.5},
offset = {x = 0, y = 0},
text = "Fuel text",
alignment = {x = 0, y = 0},
scale = {x = 100, y = 100},
})
--Later on
clicker:hud_remove(fuel_display)
Currently working on new mods.
Re: hud.remove does not work
Is the hud_remove in a minetest.after or otherwise delayed? If it's called in the same go as hud_add, removing appearently doesn't work.
-
- Member
- Posts: 324
- Joined: Sun Jun 16, 2019 20:17
- Location: x=123, y=120, z=534
Re: hud.remove does not work
The code follows a minetest.after but is not inside one.Eran wrote:Is the hud_remove in a minetest.after or otherwise delayed? If it's called in the same go as hud_add, removing appearently doesn't work.
Currently working on new mods.
Re: hud.remove does not work
Then it's propably not called with a delay. Try putting it inside a minetest.after.
minetest.after basically puts "run that function" on a To-do list for later. The code after the minetest.after call runs right away.
minetest.after basically puts "run that function" on a To-do list for later. The code after the minetest.after call runs right away.
- Krock
- Developer
- Posts: 4650
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: hud.remove does not work
This looks like yet another packet order problem.
1) Lua calls to player:hud_add and sends the packet
2) Lua calls to player:hud_remove in almost the same instant and sends the packet
3) Some time passes: network latency (even on singleplayer)
4) The client receives player:hud_remove and does nothing
5) The client receives player:hud_add and adds the hud
Long story short: Delay your HUD remove function.
1) Lua calls to player:hud_add and sends the packet
2) Lua calls to player:hud_remove in almost the same instant and sends the packet
3) Some time passes: network latency (even on singleplayer)
4) The client receives player:hud_remove and does nothing
5) The client receives player:hud_add and adds the hud
Long story short: Delay your HUD remove function.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
Who is online
Users browsing this forum: No registered users and 10 guests