解析失败,因为没有插入}?

时间:2019-05-21 13:32:05

标签: lua

设置一个Fivem服务器,并在放入自定义job_grades后尝试使esx_policejobs工作。遇到错误并停留了几个小时,我不知道我是否在这里遗漏了什么?

还有一条控制台行说堆栈回溯到另一个.lua文件,那么最终可能是那里的问题而不是实际的配置文件吗?

已经遍历了配置并确实找不到问题

    recruit = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 1500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 80 },
    },

    private = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

    private-first-class = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 }
    },

    sergeant = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

    lieutenant = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

    captain = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

    inspector = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

    deputy-chief = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

    assistant-chief = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

    chief-of-police = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },
}

不应有任何配置错误

控制台错误:

Failed to load script config.lua.
Error loading script server/main.lua in resource esx_policejob: @esx_policejob/server/main.lua:5: attempt to index a nil value (global 'Config')
stack traceback:
        @esx_policejob/server/main.lua:5: in main chunk```

2 个答案:

答案 0 :(得分:4)

问题在于表键名称中的破折号。该手册确实提示了table constructor的形式:

  
    

名称= exp形式的字段等效于[“ name”] = exp。

  

name必须为:

  
    

Lua中的名称(也称为标识符)可以是字母,数字和下划线的任何字符串,不是以数字开头也不是保留字。标识符用于命名变量,表字段和标签。

  

这意味着对于无效标识符,您必须使用表构造函数["name"] = exp的第二种形式。

['chief-of-police'] = {
    { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
    { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
    { weapon = 'WEAPON_PUMPSHOTGUN', components = { 2000, 6000, nil }, price = 70000 },
    { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
    { weapon = 'WEAPON_STUNGUN', price = 500 },
    { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
}

答案 1 :(得分:0)

您的代码“私人”保留字中的错误:

>>>>private = {
        { weapon = 'WEAPON_APPISTOL', components = { 0, 0, 1000, 4000, nil }, price = 10000 },
        { weapon = 'WEAPON_ADVANCEDRIFLE', components = { 0, 6000, 1000, 4000, 8000, nil }, price = 50000 },
        { weapon = 'WEAPON_NIGHTSTICK', price = 0 },
        { weapon = 'WEAPON_STUNGUN', price = 500 },
        { weapon = 'WEAPON_FLASHLIGHT', price = 0 },
    },

  1. 表必须构造
    myTable = {}
  1. 表存在后,您可以定义键:
    myTable["some.key"] = {}
  1. 如果您需要子键,下一步将是:
    myTable["some.key"]["sub.key"] = {}  
    myTable["some.key"]["sub.key"]["value_1"] = "123"
    myTable["some.key"]["sub.key"]["value_2"] = "456"

最后,您可以使用技巧:

    local myTables = {}
    myTables["table_name"] = myTable