hud.remove does not work

Red_King_Cyclops
Member
 
Posts: 226
Joined: Sun Jun 16, 2019 20:17
Location: Earth

hud.remove does not work

by Red_King_Cyclops » Wed Aug 21, 2019 18:18

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.
I'm working on a mod that is essentially Galacticraft for Minetest (with differences).
 

User avatar
jas
Member
 
Posts: 418
Joined: Mon Jul 24, 2017 18:15
GitHub: jastevenson303
IRC: jas_
In-game: jas

Re: hud.remove does not work

by jas » Wed Aug 21, 2019 21:11

Id is a number tho, correct?
201902221552
 

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

Re: hud.remove does not work

by Pyrollo » Thu Aug 22, 2019 06:56

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: 226
Joined: Sun Jun 16, 2019 20:17
Location: Earth

Re: hud.remove does not work

by Red_King_Cyclops » Thu Aug 22, 2019 11:32

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.
I'm working on a mod that is essentially Galacticraft for Minetest (with differences).
 

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

Re: hud.remove does not work

by Pyrollo » Thu Aug 22, 2019 12:08

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: 59
Joined: Fri May 03, 2019 16:46

Re: hud.remove does not work

by Eran » Thu Aug 22, 2019 12:10

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: 226
Joined: Sun Jun 16, 2019 20:17
Location: Earth

Re: hud.remove does not work

by Red_King_Cyclops » Thu Aug 22, 2019 16:29

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.
I'm working on a mod that is essentially Galacticraft for Minetest (with differences).
 

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

Re: hud.remove does not work

by Eran » Thu Aug 22, 2019 16:51

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: 226
Joined: Sun Jun 16, 2019 20:17
Location: Earth

Re: hud.remove does not work

by Red_King_Cyclops » Thu Aug 22, 2019 21:51

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.
I'm working on a mod that is essentially Galacticraft for Minetest (with differences).
 

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

Re: hud.remove does not work

by Eran » Thu Aug 22, 2019 22:08

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: 4346
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: hud.remove does not work

by Krock » Sun Aug 25, 2019 09:13

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.
>> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 


Return to Problems



Who is online

Users browsing this forum: No registered users and 5 guests