HudKit - refer to HUD elements by strings.
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 myhudkit = hudkit()
function example(player)
local some_data = "abcd"
if not myhudkit:exists(player, "modname:hud_1") then
myhudkit:add(player, "modname:hud_1", {
hud_elem_type = "text",
position = {x = 1, y = 0},
scale = {x = 100, y = 100},
text = some_data,
offset = {x=-100, y = 20}
})
else
myhudkit:change(player, "modname:hud_1", "text", some_data)
end
end
minetest.register_on_leaveplayer(function(player)
myhudkit.players[player:get_player_name()] = nil
end)
I created this for capturetheflag, HUDs returning IDs annoys me, I much prefer it like this.
It's more of an experiment, what do you think?
<rubenwardy> Why do HUD elements return IDs, rather than assigning a string?
<rubenwardy> like formspecs
<rubenwardy> as in, why don't you give it a name when creating it, rather than having to remember an ID.
<rubenwardy> You could use serials: num_of_hud++; local name = "mymod:hud_" .. num_of_hud
<rubenwardy> if you don't want to name it.
<rubenwardy> To maintain support, make HUD functions return the string/name, and allow mod devs to specify a string/name (or make one if they don't).
Code Snippet