Jump to content

bad argument #1 to 'pairs' (table expected, got string)


Recommended Posts

Posted

Строка с ошибкой

for k,v in pairs(data["Name"]) do

Откуда data

triggerClientEvent(root,'openwnd',root,getBOLOData('People'))
function getBOLOData(type)
for k,v in pairs(boloTable) do
	if v["Type"] == type then
		return v
	end
end
end
boloDB = dbConnect( "sqlite", "db/bolo.db" )
dbExec(boloDB, "CREATE TABLE IF NOT EXISTS bolo (Name PRIMARY KEY, Reason, Place, Type)")
boloTable = {}

function fillBOLOTable()
	local result = dbPoll(dbQuery(boloDB, "SELECT * FROM bolo"),-1)
	if result and type(result) == "table" then
		boloTable = {}
		for k,v in pairs(result) do
			v["Name"] = fromJSON(v["Name"])
			v["Reason"] = fromJSON(v["Reason"])
			v["Place"] = fromJSON(v["Place"])
			v["Type"] = fromJSON(v["Type"])
			table.insert(boloTable,v)
		end
	end
end

 

  • Moderators
Posted
On 08.06.2018 at 21:34, sqdpanda said:

Строка с ошибкой


for k,v in pairs(data["Name"]) do

Откуда data


triggerClientEvent(root,'openwnd',root,getBOLOData('People'))

function getBOLOData(type)
for k,v in pairs(boloTable) do
	if v["Type"] == type then
		return v
	end
end
end

boloDB = dbConnect( "sqlite", "db/bolo.db" )
dbExec(boloDB, "CREATE TABLE IF NOT EXISTS bolo (Name PRIMARY KEY, Reason, Place, Type)")
boloTable = {}

function fillBOLOTable()
	local result = dbPoll(dbQuery(boloDB, "SELECT * FROM bolo"),-1)
	if result and type(result) == "table" then
		boloTable = {}
		for k,v in pairs(result) do
			v["Name"] = fromJSON(v["Name"])
			v["Reason"] = fromJSON(v["Reason"])
			v["Place"] = fromJSON(v["Place"])
			v["Type"] = fromJSON(v["Type"])
			table.insert(boloTable,v)
		end
	end
end

 

у вас в data["Name"] лежит строка, а не таблица.

Developers, Developers, Developers, Developers.... © Steve Balmer

http://www.lua.org/about.html

Quote
Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...