Test if array value is nil returns error instead of nil

is it possible to test if an array key is nil?

I tried the following code in an online lua playground and in defold and got different results.

x = {}

if x[1] == nil then
  print("key value is nil, running alternate script")
end

playground returns nil and prints the message.

defold simply returns an error and doesn’t return nil

I believe there’s next() but i believe that only works in a loop and is unnecessary when working with approximate values as we are in this example.

Thanks for the help and or suggestions.

Tested on a fresh install of defold and it DOES return nil.

Trying to figure out what the discrepancy was…

Defold uses LuaJIT 2.0.3 which uses the same language features (more or less) as Lua 5.1. The basic syntax of Lua has remained the same throughout many versions now so there really shouldn’t be any difference with the snippet of code you posted.