錯誤比方說,我有一個巨大的表,是這樣的:Lua:嘗試索引一個零值;避免條件語句
test.test[1].testing.test.test_test
表不能保證存在。這些表格都不包含它。我想只能夠做到:
if test.test[1].testing.test.test_test then
print("it exits!")
end
當然只是,這會給我一個「嘗試指數(一個零值)?」的錯誤,如果任何一個指標都沒有定義。這麼多次,我最終會做這樣的事情:
if test then
if test.test then
if test.test[1] then
if test.test[1].testing then -- and so on
有沒有更好,更少繁瑣的方法來完成這個?
非常整潔的解決方案,謝謝! –