我得到的错误是 [string "function NameGen()..."]:14: attempt to compare nil with numberstack traceback: [string "function NameGen()..."]:14: in function 'NameGen' [string "function NameGen()..."]:23: in main chunk [C]: ? 我的代码:
[string "function NameGen()..."]:14: attempt to compare nil with number stack traceback: [string "function NameGen()..."]:14: in function 'NameGen' [string "function NameGen()..."]:23: in main chunk [C]: ?
我的代码:
function NameGen() preftest = math.random(100) ; syltest = math.random(100) ; sufftest = math.random(100) ; pref1 = "New "; _1syl1 = "Lon"; _2syl1 = "Don"; suff1 = " City"; prefchoice = pref1; _1sylchoice = _1syl1; _2sylchoice = _2syl; suffchoice = suff1; if preftest < 50 and _2syltest < 50 and sufftest < 50 then cityname = prefchoice .. _1sylchoice .. _2sylchoice .. suffchoice; elseif preftest < 50 and _2syltest < 50 then cityname = prefchoice .. _1sylchoice .. _2sylchoice; else cityname = _1sylchoice; end end NameGen(); print(cityname);我没有看到_2syltest被分配到哪里 – 只有syltest.如果_2syltest不是来自其他地方,那可能是问题所在,因为这是你使用该值的条件.