Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird nil value in d2d function #15

Closed
lingsamuel opened this issue Nov 26, 2024 · 1 comment · Fixed by #17
Closed

weird nil value in d2d function #15

lingsamuel opened this issue Nov 26, 2024 · 1 comment · Fixed by #17

Comments

@lingsamuel
Copy link
Contributor

lingsamuel commented Nov 26, 2024

I was facing this problem recently. In d2d function, a table with number only keys will return nil starting from a specific key.
Here is my test script:

local val = {
    [1] = 111,
    [2] = 222,
    [3] = 333,
    [4] = 444,
}

local font
d2d.register(function ()
    font = d2d.Font.new("Tahoma", 18)    
end, function ()
    for i = 1, 4, 1 do
        local text = string.format("* %d (%s) = %s", i, type(i), tostring(val[i]))
        d2d.text(font, text, 400, 1000+i*30, 0xFFFFFFFF)
    end
    local idx = 0
    for k, v in pairs(val) do
        local text = string.format("- %s (%s) = %s", tostring(k), type(k), tostring(v))
        d2d.text(font, text, 600, 1000+idx*30, 0xFFFFFFFF)
        idx = idx + 1
    end
end)

re.on_frame(function ()
    for i = 1, 4, 1 do
        local text = string.format("%d (%s) = %s", i, type(i), tostring(val[i]))
        imgui.text(text)
    end
    for k, v in pairs(val) do
        local text = string.format("%s (%s) = %s", tostring(k), type(k), tostring(v))
        imgui.text(text)
    end
end)

it outputs:
image

I have to add a random string key to the table to make it work:

local val = {
    [1] = 111,
    [2] = 222,
    [3] = 333,
    [4] = 444,
    AnyRandomKey = true,
}

image

I don't have this problem in the 2022/02/09 build (0.4.0 I guess). Only newer versions have this problem.
image

@lingsamuel
Copy link
Contributor Author

lingsamuel commented Dec 6, 2024

image
image

revert lua version fixed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant