Does Singleplayer not like loading Meta Functions? (With Bots BTW)

Titles my question basically. My meta function Player:HasPoints(amount) seems to load when ever I RE-SAVE THE LUA FUNCTION (With Lua refresh) but when I change the map, it calls nil value when I call it.

Your load order is incorrect.

When I teach Lua using GMod I tell people they need to think recursively. You’re working in a managed memory setting; meaning that load order matters for your first-load, while on auto-refresh things exist and are much-less likely to give errors when the load-order is incorrect. Basically, ensure your meta-table setter is called before the function declaration, and make sure the function declaration is called before the function call on first load. If you need help, feel free to add me.

Can you elaborate? Also it says your steam account hasnt been set up :V

You are calling it before it’s loaded, are you doing this


function meta:HasPoints()
   return tobool(self.points)

obviously yours would be different as I am using psuedocode
but what it is showing is that you are calling Player:HasPoints() above the actual function?

Basically, you have to define the metatable functions in autorun, before you actually use them. Outside of any other IFs or FUNCTIONs.

Something like this im doing

local PlayerMeta = FindMetaTable("Player")

function PlayerMeta:HasPoints(amount)


if PlayerEntity:HasPoints(50) then

it would help if you posted some code, but i think i understand what youre saying

i think acecool is trying to say something like this:

you have 3 files, a.lua, b.lua, ab.lua

ab.lua is just including things, like so

– ab.lua
include( “a.lua” ) – A is loaded before b
include( “b.lua” ) – b is loaded second

while a and b have the functions inside them like so.

– a.lua

MY_TABLE.value2 = MY_TABLE.value2 or "numero due"

function MY_TABLE:TellMeImBeautiful()
	print( "youre ok i guess" )


– b.lua


MY_TABLE.value = MY_TABLE.value or {}


now think about it this way, when the scripts are first loaded, ab will be run first (lua/autorun, or an initialize file in a gamemode)
in ab, a is included first.
in file a, the global MY_TABLE is created if it doesnt exist.
in file b, some values are added to the global MY_TABLE

now on the first run, MY_TABLE doesn’t exist when a is being run, yet it tries to index it (a nil value)
but when it is reloaded, b.lua will have been included, and MY_TABLE will exists. It won’t throw any errors.

hopefully this clears things up

edit: oh god im late, sorry. leaving this here because it might help someone later i guess

Odd, must be because its private; Find me on Steam; should be me in a suit.

Dead on example! That example will not work the first time ( print will be nil ), but the second time ( assuming the meta is set up ) will work.

That would work, but somewhere your load-order is wrong, or there’s an error, or something.

Here’s an example of my load order:

I use a recursive method for loading files, deepest first. _definitions contains meta-table definitions, colors, constants, etc. then it moves on and on. Shared first, always.

Can you show us the code, the files that include/AddCSLuaFile them starting from the 3 basic init/cl_init/shared or sh_init files: