So, I managed to fix my previous error. However, Now I have another problem. At the beginning of my code I have:
function Inv:SaveInvData( ply )
local Data = glon.encode( ply.Inv )
file.Write( "Inv/Data/" .. ply:UniqueID() .. ".txt", Data )
end
But, when I try to call it, like in here:
function Inv.LoadInvData( ply )
if ( file.Exists( "Inv/Data/" .. ply:UniqueID() .. ".txt" ) ) then
local Data = glon.decode( file.Read( "Inv/Data/" .. ply:UniqueID() .. ".txt" ) )
ply.Inv = Data
//ply:SendSavedInvItems()
else
ply.Inv = {}
ply.Inv.S1 = {}
ply.Inv.S1.full = false
ply.Inv.S1.content = ""
ply.Inv.S1.count = 0
ply.Inv.S2 = {}
ply.Inv.S2.full = false
ply.Inv.S2.content = ""
ply.Inv.S2.count = 0
ply.Inv.Swep1 = {}
ply.Inv.Swep1.class = ""
ply.Inv.Swep2 = {}
ply.Inv.Swep2.class = ""
ply.Inv.Swep3 = {}
ply.Inv.Swep3.class = ""
ply.Inv.Swep4 = {}
ply.Inv.Swep4.class = ""
ply.Inv.Swep5 = {}
ply.Inv.Swep5.class = ""
Inv:SaveInvData( ply )
end
end
hook.Add( "PlayerInitialSpawn", "LoadInvData", Inv.LoadInvData )
I get "attempted to call method SaveInvData: a nil value"
Also, Inv is defined in shared.lua like so:
Inv = {}
Inv.S1 = {}
//etc etc etc
Since I'm new to lua, this is completely boggling me.
Thanks in advance,
Jake
First of all, I don't see the table Inv created anywhere.
[lua]
local Inv = {};
[/lua]
Add that to the beginning of your file.
Second of all, that error you posted, indicates that SaveInvData is not a valid function. Did you ever create it?
[QUOTE=Capsup;16985146]First of all, I don't see the table Inv created anywhere.
[lua]
local inv = {};
[/lua]
Add that to the beginning of your file.
Second of all, that error you posted, indicates that SaveInvData is not a valid function. Did you ever create it?[/QUOTE]
I think he did. He is probably calling it before creating it however.
Maybe, but then he's not posting us enough information about it, hence we can't properly help him. :/
You guys fail at reading.
[QUOTE=jakegadget;16982779]Also, Inv is defined in shared.lua like so:
Inv = {}
Inv.S1 = {}
//etc etc etc[/QUOTE]
But that brings the question: Did you include shared.lua in the code file?
Ah, you're right. :P I didn't notice that.
Ok, so, I've look at what you've all said, and I think i found out where the problem is. I think that im creating/calling functions in the wrong order. So, Is there a rule of thumb as to which order things go in? Or does Lua execute in a particular way? I've never really used lua extensivley before, so this is all a mystery to me. Thanks in advance,
Jake
[QUOTE=jakegadget;16988189]Ok, so, I've look at what you've all said, and I think i found out where the problem is. I think that im creating/calling functions in the wrong order. So, Is there a rule of thumb as to which order things go in? Or does Lua execute in a particular way? I've never really used lua extensivley before, so this is all a mystery to me. Thanks in advance,
Jake[/QUOTE]
Always create a function before calling it. If you call a function anywhere in the code, it will not run automatically, but only when you call it.
Thank you.
While we're on the subject:
I created a function called inventory menu like so:
[code]
function InventoryMenu()
//stuff
end
[/code]
When I try to call it, I get NO error, other than the fact that the concommand doesnt exist
[code]
local function ToggleOpenInvMenu()
InventoryMenu()
InventoryMenuFrame:SetVisible( true )
end
concommand.Add( "+invmenu", ToggleOpenInvMenu )
local function ToggleCloseInvMenu()
if ( InventoryMenuFrame ) then
InventoryMenuFrame:Remove()
InventoryMenuFrame = nil
end
end
concommand.Add( "-invmenu", ToggleCloseInvMenu )
[/code]
Scratch that, the con command EXISTS, but when I run it through the console I get "Unknown Command: '-invmenu'"
EDIT:
I think this has to do with my file structure. When I use autorun/server/inv_init.lua
and autorun/client/inv_cl_init.lua
and
autorun/inv_shared.lua
it doesnt work, but it works when i put them all in the same folder. and it barely works. it gets really touchy
Sorry, you need to Log In to post a reply to this thread.