i have several hud elements in minetest game, how to align text right?…
- User
i have several hud elements in minetest game, how to align text right?
table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.5, y = 0}, offset = {x = 0, y = 23 + (i - 1) * 18}, text = "Craft wood 1/10", --text or name, alignment = {x = 0, y = 1}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.5, y = 0}, offset = {x = 0, y = 23 + (i - 0) * 18}, text = "Place chest 2/5", --text or name, alignment = {x = 0, y = 1}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, }))
- Assistant
To align the text to the right, you need to change the
alignmentvalue to{x = 1, y = 1}for both HUD elements. Here's the updated code:table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.5, y = 0}, offset = {x = 0, y = 23 + (i - 1) * 18}, text = "Craft wood 1/10", --text or name, alignment = {x = 1, y = 1}, -- Align to the right scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.5, y = 0}, offset = {x = 0, y = 23 + (i - 0) * 18}, text = "Place chest 2/5", --text or name, alignment = {x = 1, y = 1}, -- Align to the right scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, }))By setting
alignment = {x = 1, y = 1}, the text will be aligned to the right edge of the HUD element. - User
all is wrong, i need to align not only hud, but text of hud to right side of screen (like in microsoft office word)
- Assistant
I apologize for the confusion. To align the text to the right side of the screen, you need to modify the
positionandoffsetvalues. Here's the updated code:table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 1, y = 1}, -- Align to the right side of the screen offset = {x = -200, y = 23 + (i - 1) * 18}, -- Adjust the x offset to position the text text = "Craft wood 1/10", --text or name, alignment = {x = 1, y = 1}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 1, y = 1}, -- Align to the right side of the screen offset = {x = -200, y = 23 + (i - 0) * 18}, -- Adjust the x offset to position the text text = "Place chest 2/5", --text or name, alignment = {x = 1, y = 1}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, }))By setting
position = {x = 1, y = 1}and adjusting theoffsetvalue (x = -200in this example), the text will be aligned to the right side of the screen. You can adjust thexoffset value to position the text as desired. - User
I need to align each line to the right edge of the screen so that it ends in the same place (this is minetest game hud functions)
table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.9, y = 0}, offset = {x = -20, y = 0}, text = "Craft basic wood 1/10", --text or name, alignment = {x = 1, y = 1}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.9, y = 0}, offset = {x = -20, y = 0}, text = "Dig tree 10/50", --text or name, alignment = {x = 1, y = 1+2}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.9, y = 0}, offset = {x = -20, y = 0}, text = "Eat apple 10/50", --text or name, alignment = {x = 1, y = 1+4}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) - Assistant
To align each line of text to the right edge of the screen, you can adjust the
offsetvalue for each HUD element. Here's the updated code:table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.9, y = 0}, offset = {x = -200, y = 0}, -- Adjust the x offset to align to the right edge text = "Craft basic wood 1/10", --text or name, alignment = {x = 1, y = 1}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.9, y = 0}, offset = {x = -200, y = 0}, -- Adjust the x offset to align to the right edge text = "Dig tree 10/50", --text or name, alignment = {x = 1, y = 1+2}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, })) table.insert(huds, user:hud_add({ hud_elem_type = "text", position = {x = 0.9, y = 0}, offset = {x = -200, y = 0}, -- Adjust the x offset to align to the right edge text = "Eat apple 10/50", --text or name, alignment = {x = 1, y = 1+4}, scale = {x = 100, y = 100}, number = color or 0xFFFFFF, style = 4, size = 10, }))By setting
offset = {x = -200, y = 0}(you can adjust the value as needed), the text will be aligned to the right edge of the screen.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.