Lua 文本战斗系统

嗯,我正在尝试创建一个文本冒险游戏。 我目前正在创建攻击系统。 以下是代码

start = io.read()
if start == "start" then
    ma1 = "突击你的对手"
    ma2 = "勾拳你的对手"
    fa1 = "踢你的对手"
    ha1 = "用头撞你的对手"
    --近战武器
    mw1 = "拳头1"
    mw2 = "拳头2"
    foot = "踢"
    head = "用头撞"
    --魔法攻击
    ms1 = "none"
    ms2 = "none"
    ms3 = "none"
    ms4 = "none"
    --工具
    bow = "none"
    gun = "none"
    sg = "none"
    function atk()
        io.write("你要使用近战(1),魔法(2)还是科技(3)?", "\n")
        ac = io.read()
        if ac == "1" then
            io.write("你要", ma1,",", ma2, ",",fa1,",还是",ha1"?", "\n")
        end
    end
end
print(atk())

每次我运行它时,它会输出以下内容:

lua: jdoodle.lua:25: global 'ha1' is not callable (a string value)
stack traceback:
    jdoodle.lua:25: in function 'atk'
    jdoodle.lua:29: in main chunk
    [C]: in ?

因此,如果您有任何解决方案,请告诉我,谢谢。

原文链接 https://stackoverflow.com/questions/71158765

点赞
stackoverflow用户14777448
stackoverflow用户14777448

你漏掉了一个逗号:

start = io.read()
if start == "start" then
    --body
        if ac == "1" then
            io.write("Do you", ma1, ", ", ma2, ", ", fa1, ", or", ha1, "?", "\n")
        end
end
print(atk())
2022-02-21 23:58:01