我想將所有顏色值存儲在一個名爲「colors-rgb.lua」的單獨文件中,然後在需要時按名稱抓住它們。該文件的基本結構是:在Lua中使用另一個模塊時遇到問題
colorsRGB = {
aliceblue = {240, 248, 255},
antiquewhite = {250, 235, 215},
aqua = { 0, 255, 255},
aquamarine = {127, 255, 212},
azure = {240, 255, 255},
beige = {245, 245, 220},
bisque = {255, 228, 196},
black = { 0, 0, 0},
...
}
在我main.lua,我有
local colors = require("colors-rgb")
local blue = colors.colorsRGB.aliceblue
這使我的錯誤「試圖指數當地‘顏色’(一個布爾值)」
我在做什麼錯了?
在這種情況下,表格仍然可以被訪問,但它被稱爲colorsRGB,因爲它被聲明爲全局的。他應該將其聲明爲本地,然後從模塊中返回。 – user6245072
正確;儘管意圖顯然是通過'require'的結果來訪問它的。 –