【发布时间】:2014-05-07 02:47:43
【问题描述】:
我做了一个小游戏,我想检查一个玩家名字是否已经存在于“banlist”中。如果它有多个名称,我该怎么做? 例如,我有一个这样的播放器列表:
PlayerList = {'Player 1', 'Player 2', 'Player 3'}
我希望能够禁止一些玩家并将他们添加到禁止列表中,以禁止他们在游戏中做一些事情。我怎样才能做到这一点?我可以像这样使用 1 个玩家名来做到这一点:
if (Player_Name ~= 'Player 2') then
print('Hello!!')
else
print('You are banned!')
end
但这仅适用于“玩家 2”。如何添加多个名称? 我不想用“或”,像这样:
if (Player_Name ~= 'Player 2' or Player_Name ~= 'Player 3') then
print('Hello!!')
else
print('You are banned!')
end
由于我的列表可能包含超过 200 个,我不想添加超过 200 个“或”。我怎样才能简单地检查玩家是否在我创建的禁止列表中?例如:
BanList = {'Player 2', 'Player 3'}
也许是这样的(ofc 这不起作用)
if (Player_Name ~= BanList) then
print('Hello!!')
else
print('You are banned!')
end
【问题讨论】:
-
任务已经确定,直接用关键字——搜索“lua list contains”即可。