[Lua] FXManifest not importing classes like it's supposed to?

Hey, I’m developing a custom framework, but I’m stuck at this weird stuff.

My fxmanifest.lua file looks like the following:

server_scripts {
  ...
  'framework/server/classes/*.lua',
  ...
  'server/*.lua'
}

Which imports three classes:

  1. Items
  2. Jobs
  3. Player

Then, proceeding to server/base.lua I create a new thread with these inside:

ZMan.Instantiate(1) -- From Player class
ZMan.AddItem("1", "2") -- From Items class

It works fine for Instantiate but not for AddItem

Any code needed I’ll provide, thanks in advance.

Did you create an instance of the player class first in base.lua?

local player = SomeFunctionFromPlayerThatReturnsObject(someIdentifier)

You should show your player.lua source and the full source from base.lua that shows declaring the instance/object and how you’re using it.

1 Like

The error message states that AddItem is not defined.
Try to run

print(json.encode(ZMan))

you should get a bigger output. Search and check if and why AddItem is missing.

I’ve done that already, I know what the message states, and when doing that the output doesn’t contain AddItem, which literally leads me to the same place. It was known it was nil, I wrote it in the OP. Anyways I want to know why it is nil.

Alright, my bad then. In this case we need to have a look at the definition.

Since the player.lua seem to work and you think items.lua is not imported correctly add a simple print somewhere in this file, just to make sure its printed.

Ok, never thought of that for some reason, did it and it is being imported, and in the way it’s supposed to. It prints what I wrote before base.lua is imported.

So the issue persists on something else, and I can’t figure out what.

Here’s full source:

1 Like

Hello @ShahZaM,

thanks for the code. So the issue is simple. You override your own code.

	'framework/server/classes/items.lua',
	'framework/server/classes/jobs.lua',
	'framework/server/classes/player.lua',

Its loaded in this order with player beeing last and items first.
Both items and palyer.lua define a variable called ZMan and therefore override it. The last instance player.lua can use its functions correctly.

To fix this you need to define a global variable called ZMan und assign the functions and STUFF directly with
ZMan.player = {}
and so on.
I created a pull request for you which changes what I described here.

Hello, I’ve tried your solution, no success still.


Alright, my bad pushing untested code. right above your screenshot there should be an parsing error related to the affected files. While changing the structure I missed to remove the commas (,) seperating the entries in your previours structure. I removed them and this time checked with running your code. Its working, however my database is missing some entries for items so I only see alot of errors. Anyway The PR is updated.

Yeah I was avoiding pulling the request, but I did it now, thanks :slight_smile: