Nill Value Returning

Typically: "How do I... ", "How can I... " questions
Post Reply
alix
Posts: 62
Joined: 17 Sep 2019, 14:48

Nill Value Returning

Post by alix »

Hi,
I have this function from MotionPlanning scene:

Code: Select all

generatePathLengths=function(path)
    -- Returns a table that contains a distance along the path for each path point
    --for i=1, #path, 1 do
        --printToConsole(path[i])
    --end
    local d=0
    local l=6
    local pc=#path/l
    local retLengths={0}
    for i=1,pc-1,1 do
        local config1={path[(i-1)*l+1],path[(i-1)*l+2],path[(i-1)*l+3],path[(i-1)*l+4],path[(i-1)*l+5],path[(i-1)*l+6],path[(i-1)*l+7]}
        local config2={path[i*l+1],path[i*l+2],path[i*l+3],path[i*l+4],path[i*l+5],path[i*l+6],path[i*l+7]}
        d=d+getConfigConfigDistance(config1,config2)
        --printToConsole(d)
        --retLengths[i+1]=d
        table.insert(retLengths, d)
        --print(retLengths[i+1])
    end
    for i=1, #retLenghts, 1 do
        printToConsole(retLengths[i])
    end
    return retLengths
end
It has worked for me fine before, but then I don't know what happened it gives this error when i am trying to print values from retLengths..... Throughout the function, as you can see the commented PrintToConsole lines, I can print the 19 values , as follows:

Code: Select all

0.040448429027207
0.081479386441184
0.12355868558718
0.16654204371931
0.21072063183018
0.2560940060319
0.30281931954343
0.35024715469976
0.39988492808365
0.45105952853239
0.50385022504862
0.55833624737192
0.6146043240016
0.67275371326007
0.73291094779395
0.79525364546093
0.85998775021026
0.92737530111189
0.99776308425344
But As soon as the loop ends, when I try to print it says: "Lua runtime error: [string "CHILD SCRIPT Lua_script"]:478: attempt to get length of global 'retLenghts' (a nil value)"
I have tried both ways to add values of 'd' to retLengths: ''retLengths[i+1]=d'' and ''table.insert(retLengths, d)''
But as you can see the line "print(retLengths[i+1])", it prints out 19 values throughout the loop. What could be the reason for this? Everything is being calculated fine, but returning a nill, due to which further processing is stuck. Am I missing something here ???
Thanks

fferri
Posts: 1224
Joined: 09 Sep 2013, 19:28

Re: Nill Value Returning

Post by fferri »

You have a typo: retLengths vs. retLenghts (by the way, the first one has the correct spelling: length).

Post Reply