简体   繁体   中英

Lua Script:attempt to call global 'tonubmer' (a nil value)

I am new to lua,i just don't know why,does it related to environment or the libarary?it drive me crazy, i being search the answer for hours.

function gradient()
   local maxStep = 10;
   local starColor="41B0F7";
   local endColor ="1622DF";
   local sb = tonubmer(string.sub(starColor,1,2),16);
   return sb;
end
print(gradient());

There are two things going on here:

  1. Lua standard library functions like tonumber are global variables.
  2. If you try to access a global variable that does not exist (in this case, tonu* bm *er) you get nil ny default.

I recommend using a linting tool like LuaInspect to detect these typos before they bite you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM