include() broken.

I’m trying to make a dynamic MapData-style serverside inclusion system. I coded it in another gamemode, where it worked fine. Below is all the code.
[lua]include( game.GetMap() … “.lua” );[/lua]
Tested on three maps, all map lua files in the same directory, with correct spelling (eg, gm_flatgrass.lua). For some reason, I get an error saying that the file cannot be found. However, if I copy and paste the files into the garrysmod/lua folder, they work perfectly. It is serverside, being called in the InitPostEntity hook. The gamemode is new, being coded on a clean GMod install.

Any ideas why/how to get around it? This has never been an issue for me.

Are you sure game.GetMap() doesn’t return the “.bsp” at the end of the filename?

Yes.
Are the map luas in the same folder as the include()ing luas?

It works fine. As Lexic said, are they in the same directory.

What Orange said. Also, who rated me dumb? :V

Some kid with no balls tbh.

Just ignore them, the ratings don’t have any effect anyway.

Regardless, any ideas? This is like my 9th gamemode and this is the first time include() didn’t default to the gamemode directory.

include() and AddCSLuaFile() are always relative to the file they’re called in, which is why we asked you where the files were in relation to the calling script.
…Well?

I actually ran into this problem about an hour ago in my own gamemode. It appears that it includes from “gamemode” just fine when it’s included outside of a function, but within a function it defaults to “lua”, regardless of where the file it’s being included in is located. You also can’t use “…/” to change directories. My only, very hacky solution to this was to enclose the contents of the lua files in a function, include all of them, then execute the function corresponding to the lua file you want to load. It’s a real pain not having any way to set the directory of include() yourself.

Inside Function:
gamemodename/gamemode/filename

Outside function
filename

Problem solved :eng101:

^ Worked gbps. Thanks!

Ah, thanks for clearing this up, much better than that mess of a method I had to use before.