britzl / defold-richtext

Defold-RichText is a system to create styled text based on an HTML inspired markup language
MIT License
75 stars 12 forks source link

When using <a> tag along with combine_words on_click throws an error #82

Closed Qwarr closed 1 year ago

Qwarr commented 1 year ago

When combine_words = true, and you have an tag that shares a line with words not in the tag, you get the following error.

ERROR:SCRIPT: richtext/richtext.lua:586: attempt to index local 'word' (a nil value)
stack traceback:
  richtext/richtext.lua:586: in function on_click
  main/main.gui_script:64: in function <main/main.gui_script:63>

Example code that works:

    local text = "Words outside an a tag.\n<a=message_id>clickable message.</a>"
    local settings = {
        fonts = {
            pixel = {
                regular = hash("system_font"),
            },
        },
        size = 1.25,
        width = 900,
        parent = gui.get_node("center"),
        position = vmath.vector3(0, 0, 0),
        align = richtext.ALIGN_CENTER,
        combine_words = true 
    }

    self.rt_text = richtext.create(text, "pixel", settings)

And when you add some words on the same line as the tag:

local text = "Words outside an a tag.\nThis is <a=message_id>clickable message.</a>"

This will give the above error.

However I noticed if you change it to this:

local text = "Words outside an a tag.\nThis is a <a=message_id>clickable message.</a>"

Suddenly it works again.

When combine_words = false none of this breaks.

britzl commented 1 year ago

Fixed in https://github.com/britzl/defold-richtext/commit/4a11e701d0c9ebb4a6f99023aae6e05fd29ec79b