Lua报错unexpected symbol near ')',求排查esx_society脚本问题
ESX脚本报错:LUA unexpected symbol near ')' 原因分析
错误根源
报错指向的local society = 'society_mechanic', function(society)这一行存在严重问题:
- 语法规则违反:Lua不允许在赋值语句后直接拼接匿名函数声明,这种混乱写法让解析器无法识别符号,直接抛出
unexpected symbol near ')'错误。 - 冗余代码误插入:行尾的
, function(society)属于完全多余的内容,应该是编写或粘贴代码时的失误,把其他逻辑片段误放到此处。 - 变量重复声明问题:就算去掉多余的function部分,这里用
local society重新声明函数参数里的同名变量,会覆盖传入的参数值,逻辑上也不合理。
修正后的代码示例
RegisterServerEvent('esx_society:depositMoney') AddEventHandler('esx_society:depositMoney', function(society, amount) local xPlayer = ESX.GetPlayerFromId(source) -- 优先使用传入的协会参数,无参数时默认使用mechanic协会 local targetSociety = society or 'society_mechanic' if amount > 0 and xPlayer.get('money') >= amount then TriggerEvent('esx_addonaccount:getSharedAccount', targetSociety, function(account) xPlayer.removeMoney(amount) account.addMoney(amount) end) TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount)) else TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount')) end end)
关键修正点
- 删除了语法错误的行,替换为逻辑合理的变量赋值逻辑
- 用新变量
targetSociety避免覆盖原函数参数,同时保留默认协会的灵活性 - 修正了
getSharedAccount的调用参数(原代码中society.account是错误用法,应直接传入协会名称字符串)
内容的提问来源于stack exchange,提问作者Chnewi
相关产品推荐
相关产品推荐

