Update Hello-World.md
parent
ca700d533c
commit
45a830049f
|
@ -6,7 +6,7 @@ HUD stuff
|
|||
minetest.register_on_joinplayer(function(player)
|
||||
local hud_id = player:hud_add({
|
||||
hud_elem_type = 'text',
|
||||
text = 'First text',
|
||||
text = 'Hello world!',
|
||||
number = 0xFFFFFF,
|
||||
position = {x=0, y=1},
|
||||
alignment = {x=1, y=-1},
|
||||
|
@ -14,3 +14,48 @@ minetest.register_on_joinplayer(function(player)
|
|||
})
|
||||
end)
|
||||
```
|
||||
|
||||
Modify HUD text via formspec. Doesn't work in Minimal.
|
||||
|
||||
```Lua
|
||||
-- Show form when the /formspec command is used.
|
||||
minetest.register_chatcommand("formspec", {
|
||||
func = function(name, param)
|
||||
minetest.show_formspec(name, "tutorial:form",
|
||||
"size[4,3]" ..
|
||||
--"label[0,0;Hello, " .. name .. "]" ..
|
||||
"field[1,1.5;3,1;word;Enter name;]" ..
|
||||
"button_exit[1,2;2,1;exit;Save]")
|
||||
end
|
||||
})
|
||||
|
||||
-- Register callback
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "tutorial:form" then
|
||||
-- Formname is not mymod:form,
|
||||
-- exit callback.
|
||||
return false
|
||||
end
|
||||
|
||||
-- Send message to player.
|
||||
changeText(player, fields.word)
|
||||
|
||||
-- Return true to stop other minetest.register_on_player_receive_fields
|
||||
-- from receiving this submission.
|
||||
return true
|
||||
end)
|
||||
|
||||
function changeText(player, word)
|
||||
local newString = "Hello, " .. word .. "!"
|
||||
player:hud_change(hold.hud_id, 'text', newString)
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
## Hello Pickaxe
|
||||
|
||||
```Lua
|
||||
minetest.register_tool("tutorial:hellopick", {
|
||||
inventory_image = "tutorial_tool_hellopick.png",
|
||||
})
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue