函数只返回一个值,而不是lua中的两个值
我试图返回name和name2的值,但是返回的只是第一个值。我对lua比较新,而且一般都会编写代码,所以我只是想学习一下 调用此函数的其他位置:函数只返回一个值,而不是lua中的两个值,lua,return,fivem,Lua,Return,Fivem,我试图返回name和name2的值,但是返回的只是第一个值。我对lua比较新,而且一般都会编写代码,所以我只是想学习一下 调用此函数的其他位置: function GetCharacterName(source) local xPlayer = QBCore.Functions.GetPlayer(source) local name = xPlayer.PlayerData.charinfo.lastname local name2 = xPlayer.PlayerData.cha
function GetCharacterName(source)
local xPlayer = QBCore.Functions.GetPlayer(source)
local name = xPlayer.PlayerData.charinfo.lastname
local name2 = xPlayer.PlayerData.charinfo.firstname
if xPlayer then
return name, name2
end
end
本地名称1,名称2=GetCharactersName()本地名称1,名称2=GetCharactersName()可能有两个原因
GetCharacterName(source)
不是表达式列表中的最后一个,或者如果将该函数调用放在括号中或将其分配给单个变量RegisterServerEvent("mdt:performVehicleSearchInFront")
AddEventHandler("mdt:performVehicleSearchInFront", function(query)
local usource = source
local xPlayer = QBCore.Functions.GetPlayer(usource)
if xPlayer.job.name == 'police' then
exports['ghmattimysql']:execute("SELECT * FROM (SELECT * FROM `mdt_reports` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(reports)
for r = 1, #reports do
reports[r].charges = json.decode(reports[r].charges)
end
exports['ghmattimysql']:execute("SELECT * FROM (SELECT * FROM `mdt_warrants` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(warrants)
for w = 1, #warrants do
warrants[w].charges = json.decode(warrants[w].charges)
end
exports['ghmattimysql']:execute("SELECT * FROM `player_vehicles` WHERE `plate` = @query", {
['@query'] = query
}, function(result)
local officer = GetCharacterName(usource)
TriggerClientEvent('mdt:toggleVisibilty', usource, reports, warrants, officer, xPlayer.job.name)
TriggerClientEvent("mdt:returnVehicleSearchInFront", usource, result, query)
end)
end)
end)
end
end)
在这种情况下,GetCharacterName的结果列表被设置为1个值(名称),因为您只分配给单个变量。如果需要两个返回值,则需要两个变量
要么这样做:
local charname = GetCharacterName(usource)
例如,charName是“特朗普,唐纳德”
或者将该名称作为单个字符串返回:
local lastName, firstName = GetCharactername(usource)
local charName = lastName .. ", " .. firstname
然后,
localcharname=GetCharacterName(usource)
将起作用可能有两个原因
GetCharacterName(source)
不是表达式列表中的最后一个,或者如果将该函数调用放在括号中或将其分配给单个变量RegisterServerEvent("mdt:performVehicleSearchInFront")
AddEventHandler("mdt:performVehicleSearchInFront", function(query)
local usource = source
local xPlayer = QBCore.Functions.GetPlayer(usource)
if xPlayer.job.name == 'police' then
exports['ghmattimysql']:execute("SELECT * FROM (SELECT * FROM `mdt_reports` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(reports)
for r = 1, #reports do
reports[r].charges = json.decode(reports[r].charges)
end
exports['ghmattimysql']:execute("SELECT * FROM (SELECT * FROM `mdt_warrants` ORDER BY `id` DESC LIMIT 3) sub ORDER BY `id` DESC", {}, function(warrants)
for w = 1, #warrants do
warrants[w].charges = json.decode(warrants[w].charges)
end
exports['ghmattimysql']:execute("SELECT * FROM `player_vehicles` WHERE `plate` = @query", {
['@query'] = query
}, function(result)
local officer = GetCharacterName(usource)
TriggerClientEvent('mdt:toggleVisibilty', usource, reports, warrants, officer, xPlayer.job.name)
TriggerClientEvent("mdt:returnVehicleSearchInFront", usource, result, query)
end)
end)
end)
end
end)
在这种情况下,GetCharacterName的结果列表被设置为1个值(名称),因为您只分配给单个变量。如果需要两个返回值,则需要两个变量
要么这样做:
local charname = GetCharacterName(usource)
例如,charName是“特朗普,唐纳德”
或者将该名称作为单个字符串返回:
local lastName, firstName = GetCharactername(usource)
local charName = lastName .. ", " .. firstname
然后,
local charname=GetCharacterName(usource)
将起作用输入本地崩溃服务器输入本地崩溃服务器可能的解决方法?问题是什么?1.还是2。?我不能帮你这么少的代码和信息,如果我把它放在第一位或删除它的名字,Name2将填充一个结果。我只是不能让他们同时给出一个结果。所以我假设是2。GetCharacterName()函数在该脚本中被调用7次,以定义其自身的局部变量请添加一些代码,说明如何在问题中使用该函数。这比试图解释你所做的要好得多,我添加了两个调用它的实例。它基本上会以类似的方式被额外调用3-4次。可能的解决方法是什么?问题是什么?1.还是2。?我不能帮你这么少的代码和信息,如果我把它放在第一位或删除它的名字,Name2将填充一个结果。我只是不能让他们同时给出一个结果。所以我假设是2。GetCharacterName()函数在该脚本中被调用7次,以定义其自身的局部变量请添加一些代码,说明如何在问题中使用该函数。这比试图解释你所做的要好得多,我添加了两个调用它的实例。它基本上会以类似的方式被额外调用3-4次。