hud.remove does not work

Post Reply
Red_King_Cyclops
Member
Posts: 324
Joined: Sun Jun 16, 2019 20:17
Location: x=123, y=120, z=534

hud.remove does not work

by Red_King_Cyclops » Post

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.

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: hud.remove does not work

by jas » Post

Id is a number tho, correct?

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: hud.remove does not work

by Pyrollo » Post

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
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

Red_King_Cyclops
Member
Posts: 324
Joined: Sun Jun 16, 2019 20:17
Location: x=123, y=120, z=534

Re: hud.remove does not work

by Red_King_Cyclops » Post

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
I tried that. I found about hud.remove in Rubenwardy's modding book.
Currently working on new mods.

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: hud.remove does not work

by Pyrollo » Post

Have you checked that your stored ID is still the good one ?

EDIT: Maybe, post some code
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: hud.remove does not work

by Eran » Post

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.

Red_King_Cyclops
Member
Posts: 324
Joined: Sun Jun 16, 2019 20:17
Location: x=123, y=120, z=534

Re: hud.remove does not work

by Red_King_Cyclops » Post

I'm using version 5.0.1. My code looks like this:

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)
Notice that this code is very WIP.
Currently working on new mods.

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: hud.remove does not work

by Eran » Post

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.

Red_King_Cyclops
Member
Posts: 324
Joined: Sun Jun 16, 2019 20:17
Location: x=123, y=120, z=534

Re: hud.remove does not work

by Red_King_Cyclops » Post

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.
The code follows a minetest.after but is not inside one.
Currently working on new mods.

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: hud.remove does not work

by Eran » Post

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.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: hud.remove does not work

by Krock » Post

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.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests