Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

i have several hud elements in minetest game, how to align text right?…

  1. 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, }))

  2. Assistant

    To align the text to the right, you need to change the alignment value 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.

  3. 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)

  4. Assistant

    I apologize for the confusion. To align the text to the right side of the screen, you need to modify the position and offset values. 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 the offset value (x = -200 in this example), the text will be aligned to the right side of the screen. You can adjust the x offset value to position the text as desired.

  5. 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,
    		}))
    
  6. Assistant

    To align each line of text to the right edge of the screen, you can adjust the offset value 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.