Using variables across folders

I am using dark rp modification and I need to access the variables in /lua/darkrp_customthings/jobs.lua from /lua/darkrp_modules/somefolder/some.lua

However when I attempt to access them I get nil. Also, when i try to include the jobs file, it actually tries to run the job lua again, resulting in errors. I also tried abstracting the variables to a separate file, including that file in both jobs.lua and some.lua but I got the same nil problem. Is there any way I can pass along instances of variables to files that can’t see them?

Heh, people still think darkrpmodification is for anything else than modification of core files.

Also, DarkRP has it’s own forums you know - http://forum.darkrp.com/

Yeah I’ve tried posting there, but the community isn’t as active, and I’ve got a lot more helpful advice from here.

So you are saying that if I am creating a darkrp_module, it should go in the addons folder outside of the darkrpmodification folder? I was using this as a template to build my entity from. I just assumed that, because the folders were named darkrp_config, darkrp_modules etc, and because they mapped to the folder structure of the darkrpmodification folder, that I was supposed to place them in there.

Also in the customthings/jobs.lua file, there is a message stating - “This file contains your custom jobs”.
Even if I do define those jobs in my own folder in addons, I still need to export the variables in some way as one of the modules i’m creating need to do certain things to certain jobs

For the moment I am using Get/Set GlobalInt, with a key that is a string representation of the job enum, but that is obviously not optimal as it makes the code pretty brittle. Any alternative suggestions are welcome

You don’t need to make a module to create addons for DarkRP lol.

no shit sherlock, but the addon im making happens to be a module

Why are you even posting here if you are gonna be condescending and unhelpful?

Why are you posting here if you don’t want people giving you advices?

Oh, well - I’m out, stay stupid.

my question wasn’t about how to structure my project, it was about how to make a value defined in one area accessible to a file in a completely separate area. You pointed me to a different forum and then told me that a module isn’t necessary for an addon. If you don’t know how to answer the question, that’s fine, but don’t post here if you don’t have an actual suggestion for me

Give a specific usage case; there’s a lot of different ways to access different variables.

So I have a list of jobs defined in the jobs.lua darkrp modification. several of those jobs need to be notified every x amount of minutes of a change in events. Because the events are specific to these jobs and not generic, and because the events will only be displayed on the hud, I created an sv_announcements.lua file in my hud folder that is in my darkrp modules folder. That way, I can set a nw string for each player every x minutes. Then in my cl_hud main file, it picks up the current nw string and displays it on the users hud. I currently have it set up so that, after each job in the jobs.lua, i set a global int that is equal to a string representation of the job name, i.e. SetGlobalInt(“TEAM_EXAMPLE”, TEAM_EXAMPLE). Then I can call GetGlobalInt(“TEAM_EXAMPLE”) in the sv_announcements.lua to reinstantiate the enums. However this seems pretty hacky and a really roundabout way to do something that i feel like there is a much better solution to.

Enums are global. You can access them in both realms (since jobs.lua is included shared) just using the enum. If that’s not the case, then it sounds like a loading issue with DarkRP. If you need the table of jobs, then you can store it to the DarkRP table.

Yeah, i saw they were defined without any local prefix, and I had no trouble accessing them from different lua files within the same folder (darprp config) but as soon as I leave the folder, they no longer are visible and I get null references everywhere. I tried including the jobs.lua file in my sv_announcements file, but it seemed to include it similar to how C might include a file, in that it appended it to the top and tried to run through the whole file again, resulting in an error saying that the first job already existed. I am able to access the jobs table easy enough, and I am able to access the job a given player has using ply:Team(), but the problem was that ply:Team() returned an int value that I need to compare to the enums.

One thing I have been considering is moving my sv_announcements file into my darkrp config folder just to get that visibility. Because it stores the announcements in the NWString table, It’s not really crucial that it be located in the same folder as the hud files, even though it is directly related to their operation

By a module, do you mean you’re actually calling module? If so, your value is nil because the environment is different. Use package.seeall as the second parameter of the module function and then assign your variable globally through _G

Thank you so much sannys, that is exactly what I was looking for. After reading a bit on it, it turns out modules are created in a separate environment from the global one, meaning any global variables defined there get stored on the module table and any global variables outside of it can’t be seen, but giving it package.seeall gives it a reference to a global table to allow use of those variables (at the cost of security as global variables can now be accessed through the module)

Seriously, thanks a bunch