• Table value not being set?
    7 replies, posted
So for some odd reason, it's not storing values in my table. [lua] society.Plugin = {} society.Plugin.Hooks = { } function society.Plugin.InitialisePlugins() for k, v in pairs( file.FindInLua( "Society/gamemode/systems/plugins/*.lua" ) ) do include( "Society/gamemode/systems/plugins/" .. v ) end end -- wtf. function ccit() print( "plugin .. " .. tostring(table.concat( society.Plugin.Hooks, " " )) ); end concommand.Add("ccit", ccit) function society.Plugin:AddCustomHook( tbl, hook, func ) self.Hooks[ tbl.Name ] = { hook = func }; -- This isn't setting for some odd reason. print( "plugin .. " .. tostring(table.concat( self.Hooks, " " )) ); print("Added " .. tostring( tbl.Name ) .. " to plugin hooks with hook variable of" .. tostring(hook)) -- This returns values, tbl.Name and hook are both valid strings. end function society.Plugin.RegisterPlugin( table ) if ( table.Name and table.Description and table.Author and table.Initialise and table.Version != nil) then print("Society:: Loaded Plugin" .. tostring(table.Name) .. ": " .. tostring(table.Description) .. ": " .. table.Version .. ", by " .. tostring(table.Author) .. "." ) table.Initialise() --[[ if ( table.DisconnectSave ) then hook.Add( "PlayerDisconnected", table.Name .. "PlayerDisconnected", table.DisconnectSave ) end if ( table.PlayerConnect ) then hook.Add( "PlayerConnect", table.Name .. "PlayerConnect", table.PlayerConnect ) end if ( table.PlayerSpawn ) then hook.Add( "PlayerSpawn", table.Name .. "PlayerSpawn", table.PlayerSpawn) end --]] if ( table.CustomHooks == true ) then for k,v in pairs( society.Plugin.Hooks[ table.Name ] ) do if ( society.Plugin.Hooks[ table.Name ][ v ] != nil ) then print("??????????????") hook.Add( tostring(v), table.Name .. tostring(v), society.Plugin.Hooks[ table.Name ][ v ] ) -- society.Plugin.Hooks[ table.Name ][ v ] should be a function? end end end end end[/lua] Here is where I'm calling the function that sets the values. [lua] local Plugin = {} Plugin.Name = "Footsteps" Plugin.Description = "A more, tropical, sound." Plugin.Author = "LauScript" Plugin.Version = "1.0" Plugin.CustomHooks = true function TestThisShit() print( "Test" ) end society.Plugin:AddCustomHook( Plugin, "PlayerSpawn", TestThisShit ) function Plugin.Initialise() end society.Plugin.RegisterPlugin( Plugin ) [/lua] kind of rusty haven't coded in awhile
Error and line of error might help and the prints from the console
Okay, there is no error at all. So.. As for the prints, [lua] print("Added " .. tostring( tbl.Name ) .. " to plugin hooks with hook variable of" .. tostring(hook))[/lua] on line 19 returns exactly what it should, it returns "Added Footsteps to plugin hooks with hook variable of PlayerSpawn" And if you notice on line 18, I put [lua] print( "plugin .. " .. tostring(table.concat( self.Hooks, " " )) ); [/lua] and that prints when the society.Plugin:AddCustomHook function is called, it just prints "plugin .. " On the if then else check at line 42 i have [lua] society.Plugin.Hooks[ table.Name ][ v ] != nil [/lua] seems to be returning nil, because nothing in that check is getting called( the print("????????????") inside the statement doesn't show up )
bump
[Lua] function society.Plugin:AddCustomHook( tbl, hook, func ) self.Hooks[ tbl.Name ] = {} self.Hooks[ tbl.Name][hook] = func MsgN("Added " .. tostring( tbl.Name ) .. " to plugin hooks with hook variable of" .. tostring(hook)) end function society.Plugin.RegisterPlugin( table ) if ( table.Name and table.Description and table.Author and table.Initialise and table.Version != nil) then --print("Society:: Loaded Plugin" .. tostring(table.Name) .. ": " .. tostring(table.Description) .. ": " .. table.Version .. ", by " .. tostring(table.Author) .. "." ) table.Initialise() --[[ if ( table.DisconnectSave ) then hook.Add( "PlayerDisconnected", table.Name .. "PlayerDisconnected", table.DisconnectSave ) end if ( table.PlayerConnect ) then hook.Add( "PlayerConnect", table.Name .. "PlayerConnect", table.PlayerConnect ) end if ( table.PlayerSpawn ) then hook.Add( "PlayerSpawn", table.Name .. "PlayerSpawn", table.PlayerSpawn) end --]] if ( table.CustomHooks == true ) then for k,v in pairs( society.Plugin.Hooks[table.Name] ) do if ( society.Plugin.Hooks[table.Name][k] != nil ) then hook.Add( tostring(k), table.Name.."-" .. tostring(k), v ) end end end end end [/LUA] Fixed
What'd you do? I like to learn frm these things. After looking over it, it seems you changed just the "format" as i like to call it, of the way it's saving to the table? And using the k value which for some reason excluded
you cant do Self.Hooks[tbl.Name] = {hook = func} If you do it that way then the key will be set as "hook" and not the name of the hook. Also when you then call in pairs k is returned as the hook name and v is returned as the function. So basically the table looks like Hooks = {} Hooks["Footsteps"] = {} Hooks["Footsteps"]["PlayerSpawn"] = function and we are calling "Hooks["Footsteps"]" in pairs so it is returned as k = "PlayerSpawn" v = function
[QUOTE=Remscar;30784625]you cant do Self.Hooks[tbl.Name] = {hook = func} If you do it that way then the key will be set as "hook" and not the name of the hook. Also when you then call in pairs k is returned as the hook name and v is returned as the function. So basically the table looks like Hooks = {} Hooks["Footsteps"] = {} Hooks["Footsteps"]["PlayerSpawn"] = function and we are calling "Hooks["Footsteps"]" in pairs so it is returned as k = "PlayerSpawn" v = function[/QUOTE] Excellent, yeah see that's my problem, I can't visualise what the table looks like so it gets confusing for me, but I pretty much got it down now! Thanks!
Sorry, you need to Log In to post a reply to this thread.