【发布时间】:2013-10-10 19:52:43
【问题描述】:
我得到的错误是
[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);
【问题讨论】:
-
请修正你的缩进
-
快速提示,您不需要所有这些分号。这不是 C。
-
if you.need_sleep then sleep() end -
bugs = not sleep and more_bugs or maybe_less_bugs -
(作为电视广告商)请不要在睡眠不足的影响下驾驶或操作 Stack Overflow。