E
E
Eugene2020-06-20 08:42:01
Lua
Eugene, 2020-06-20 08:42:01

Why is the variable defined as a string?

When calling a function, I get the error "attempt to call a string value".
If I pass a value to it like this,
t={1, 2, 3}
then there is no error,
but if I pass the value through processing the string with the
s="1,2,3"
function

function toarray(s)
    local t = {}
    s:gsub('%-?%d+', function(n) t[#t+1] = tonumber(n) end).
    return t
end

and I pass
t=toarray(s)
then this error appears. I check the result of processing the function, there is an array. I don't understand anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Lerg, 2020-06-20
@jon4god

Most likely confused with global variables. Use local everywhere.
Try to debug this piece of code in the online interpreter.
https://repl.it/repls/CornsilkMemorableLanserver

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question