ERROR: [string "LuaVM"]:219: attempt to index a nil value (global 'math')

2.3k Views Asked by At

I get an error in the script below. I wrote the error code and lines under the script. Please help someone. I have been getting this error for a few days.

These are the lines with errors

[string "LuaVM"]:219: attempt to index a nil value (global 'math')

function convert_sens(unconvertedSens) 
return 0.002 * math.pow(10, unconvertedSens / 50)
end

function calc_sens_scale(sensitivity)
return convert_sens(sensitivity)/convert_sens(50)
end
1

There are 1 best solutions below

3
On

It looks like the Lua interpreter you are using doesn't pre-load math library. You can try adding local math = require "math" statement at the beginning of your script, but if this doesn't work, you need to provide more details about your Lua environment. It's possible that access to the math library is not provided.