math.randomseed(os.time())

时间:2016-05-23 21:59:51

标签: lua syntax-error

我正在为LUA中的脚本武器创建一些代码,我不会随意发出3种爆炸声。它似乎不起作用,我得到这个错误 -

    syntax error near unexpected token 'os.time'

这是脚本的片段,似乎是错误的来源 -

    math.randomseed( os.time() )
    local expthink = math.random(3,5)
    if expthink == 3 then local explosionsound = "explode3.wav"
    elseif expthink == 4  then local explosionsound = "explode4.wav"
    elseif expthink == 5 then local explosionsound = "explode5.wav"
    end

另外我在Git Bash中运行我的test.lua文件,所以我可以看到输出,这会影响到什么吗?

这是我在命令提示符下输出的输出:

Click to see Image

(发布图片的声誉不够)

1 个答案:

答案 0 :(得分:0)

感谢@KeithThompson的回答。

只是不要将explosionionsound变量定义为local。

    math.randomseed(os.time())
    local expthink = math.random(3,5)
    if expthink == 3 then explosionsound = "explode3.wav"
    elseif expthink == 4  then explosionsound = "explode4.wav"
    elseif expthink == 5 then explosionsound = "explode5.wav"
    end
    print(explosionsound)

感谢@EgorSkriptunoff的编辑 - 编辑:另外,在Bash中运行它不是一个好主意。 Bash与lua文件不兼容,就像批处理文件一样。它将它作为bash脚本运行,但它没有看到         math.randomseed(os.time()) 正确的语法。

相关问题