resource.AddFile

I tried searching around on facepunch and gmod wiki but it seems to me that i’m doing it right. Still can’t get it to work though, the error is:


acheSound' (a nil value)
Failed to load sound "sound\zeldasong1.wav", file probably missing from disk/repository
R

and



--- Missing Vgui material materials


This is in the init.lua obviously.



function GM:Initalize() // Adding files.
    
    resource.AddFile("sound/zeldasong1.wav")
    resource.AddFile("materials/test.vtf")
    resource.AddFile("materials/test.vmt")

end


This is a gamemode.

[lua]
resource.AddFile(“sound/zeldasong1.wav”)// Adding files.
resource.AddFile(“materials/test.vmt”)

function GM:Initalize()
end
[/lua]

That didn’t work.

here is a pastebins if that could help. I’ll recheck over my files to make sure they are actually there but I’ve checked several times.

Do i have to use it like this maybe?


 resource.AddFile("garrysmod/sound/zeldasong1.wav") 

‘Didn’t do anything’

shared.lua
http://pastebin.com/T7gM5aPM

init.lua
http://pastebin.com/zrRjetNZ

cl_init.lua
http://pastebin.com/F9Rhc8k2

resource.AddFile doesn’t always work, it’s a known bug.

Don’t call resource.AddFile in any function just put it under the includes().

It starts in the garrysmod/garrysmod directory.

No it isn’t. It works fine.

It is. Also has been reported multiple times in the niggles thread.

If I recall correctly, it was only you that posted it in the niggles thread.

That didn’t seem to work. I’ll try working with resource.AddSingleFile I suppose. Also i am certain that the files are where they are suppose to be.

Can you post the whole error? The first bit is cut off. How are you using *util.PrecacheSound() *?

The precache isn’t doing it, i’ll fix that now. It was a SWEP problem.



Lua initialized (Lua 5.1)
Registering gamemode 'NL' derived from 'base'
ScriptEnforce is disabled
Compressing lua files into data pack..
Skipped. Datapack exists.
Executing listen server config file
exec: couldn't exec listenserver.cfg
Browser Message: Uncaught ReferenceError: SetStatusChanged is not defined - :0
[L] Testing
Map: gm_flatgrass
Players: 1 / 8
Build: 4632
Server Number: 4

No pure server whitelist. sv_pure = 0
Decompressing data pack into virtual file system..
Data pack loaded: 229 files. (0.046s)
Lua initialized (Lua 5.1)
--- Missing Vgui material materials/test
Registering gamemode 'NL' derived from 'base'
Sending 8 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Scanning for downloaded fonts..
Reloading Particles..
[gamemodes
l\entities\weapons\weapon_rocket\shared.lua:43] attempt to call field 'PrechacheSound' (a nil value)
Failed to load sound "sound\zeldasong1.wav", file probably missing from disk/repository
Redownloading all lightmaps


Weird thing is I downloaded other gamemodes that use resource.addfile and tried copying some of the files they using onto my gamemode. And it still wouldn’t load them. I think I’ll try to reinstall.

Have you tried checking if the files can be accessed from within GMod, using file.Exists?

Reinstalling it worked, thanks for the help.

Check this code i have if you want to add all files in a directory use this code.
Make a file like contentdownload.lua paste this code in put the directory’s in and place the lua file in lua/autorun/server



function AddDir(dir) // recursively adds everything in a directory to be downloaded by client
    local list = file.FindDir("../"..dir.."/*")
    for _, fdir in pairs(list) do
        if fdir != ".svn" then // don't spam people with useless .svn folders
            AddDir(dir.."/"..fdir)
        end
    end
 
    for k,v in pairs(file.Find("../"..dir.."/*")) do
        resource.AddFile(dir.."/"..v)
    end
end
 
AddDir("target/to/the/directory")
AddDir("target/to/the/directory")


To be honest, my fail safe way of resource.AddFile is through a autorun lua file, with nothing BUT resource.addfiles’s and they have to be consistent. They all have to be properly aligned, no extra spaces, etc.

I find that resource.AddFile is very weird, it works sometimes, and other times it doesn’t.

I suggest creating a lua file called download.lua and putting it in lua/autorun/server

Then putting the [lua]resource.AddFile[/lua] in there.

That’s assuming your using a server.

Does it work if I just paste that on the download.lua? or do I have to add something else?
I’m sorry I’m very new at coding.

I’d suggest using resource.AddSingleFile. I made a recursive resources.lua file which adds all content in my content directory automatically and that’s the function I use without any issues.