• Returning '
    7 replies, posted
I'm doing extensive edits for this plugin: [url]http://www.facepunch.com/showthread.php?t=980687[/url] But I'm getting this absolutely ball-busting error that confuses the crap outta me: [CODE][ERROR] addons/ulx/lua/includes/modules/sourcebans.lua:247: attempt to index upvalue 'database' (a nil value) 1. loadAdmins - addons/ulx/lua/includes/modules/sourcebans.lua:247 2. reset - addons/ulx/lua/includes/modules/sourcebans.lua:809 3. unknown - addons/ulx/lua/includes/modules/sourcebans.lua:815 4. unknown - lua/includes/modules/concommand.lua:69[/CODE] Here is the relevant snippit: [CODE] function loadAdmins() admins = {}; adminGroups = {}; adminsByID = {}; local query = database:query(queries["Select Admin Groups"]:format(config.dbprefix)); query.onFailure = adminGroupLoaderOnFailure; query.onSuccess = adminGroupLoaderOnSuccess; query:start(); notifymessage("Loading Admin Groups . . ."); end local function reset() local Players = player.GetAll(); for i = 1, table.Count(Players) do local ply = Players[i] ply:SetUserGroup("user"); end loadAdmins(); end concommand.Add("sm_rehash", function(ply, cmd) if (ply:IsValid()) then return not4u(ply, cmd); end notifymessage("Rehash command recieved, reloading admins:"); reset(); end, nil, "Reload the admin list from the SQL");[/CODE] What does this error even mean and how can I fix it? EDIT Sorry about the title it won't let the change go through or some aggressive db caching is going on!
database doesn't exist; I'm still unfamiliar with MySQL module's syntax, but if I were to take a guess I'd say you're trying to use functions from a module you either haven't loaded or don't have.
That didn't happen before and if you check the original plugin in "function loadAdmins()" database is never defined since it's a global variable.
database is nil, that is your problem, why it is nil is impossible for me to say, though it is likely something to with gmsv_mysqlloo.dll not being loaded properly.
Just a note... [lua] local function reset() local Players = player.GetAll(); for i = 1, table.Count(Players) do local ply = Players[i] ply:SetUserGroup("user"); end loadAdmins(); end[/lua] What are you doing? Why are you not just doing for k, ply in pairs( player.GetAll() ) do ply:SetUserGroup("user") end? table.Count loops through the table and for every index increases a number, then at the end of that loop, returns that number. This looks like you're intentionally making your script unoptimized.
[QUOTE=.\\Shadow};40331928]Just a note... [lua] local function reset() local Players = player.GetAll(); for i = 1, table.Count(Players) do local ply = Players[i] ply:SetUserGroup("user"); end loadAdmins(); end[/lua] What are you doing? Why are you not just doing for k, ply in pairs( player.GetAll() ) do ply:SetUserGroup("user") end? table.Count loops through the table and for every index increases a number, then at the end of that loop, returns that number. This looks like you're intentionally making your script unoptimized.[/QUOTE] Can you explain that clearer I'm a bit confused D:
[QUOTE=silenceheaven;40339588]Can you explain that clearer I'm a bit confused D:[/QUOTE] table.Count does a loop through the table. So, you'd be better off doing for k, v in pairs( Players ) than what you're doing now. table.Count would be something like this... [lua] function table.Count( tbl ) local num = 0 for k, v in pairs( tbl ) do num = num + 1 end return num end [/lua]
[QUOTE=Greetings;40339759]table.Count does a loop through the table. So, you'd be better off doing for k, v in pairs( Players ) than what you're doing now. table.Count would be something like this... [lua] function table.Count( tbl ) local num = 0 for k, v in pairs( tbl ) do num = num + 1 end return num end [/lua][/QUOTE] Ahhhh! Alright thanks for the clarification mate!
Sorry, you need to Log In to post a reply to this thread.