In my first attempt at writing my own script from scratch, there is one thing I can’t seem to figure out. As the topic title says, how is code from server files read/executed?
The top of my server script looks like this:
--
-- If we grab Config values up here, does server keep them in memory, making them safe to use?
--
local trucks = Config.Trucks
local boxTrucks = Config.BoxTrucks
local dumpTrucks = Config.DumpTrucks
local fluidTrucks = Config.FluidTrucks
local truckData = Config.TruckData
local poiData = Config.POI
local cargoData = Config.CargoTypes
print('Initiated config values')
As you can see I’m trying to save some tables from the config file to local variables. Some of these tables do actually seem to be filled with data from the config, and others stay nil. It also seems like at different places in the script, some might be filled that weren’t earlier on in the script.
One solution I have found searching the internet was to make sure that the config file is loaded first in fxmanifest, which it is, I put it at the very top.
shared_scripts {
'config.lua',
'@someplugin/client.lua' -- calling a client script from server side here, is that ok?
}
server_scripts {
--'config.lua', also tried putting it here
'@oxmysql/lib/MySQL.lua',
'server.lua'
}
client_scripts {
--'config.lua', and here
'@someplugin/client.lua',
'@someplugin/client.lua',
'client.lua'
}
And just for being complete, my config file really does contain all the tables mentioned:
Config = {}
Config.Trucks = { 'scrap' }
Config.BoxTrucks = { 'scrap' }
Config.DumpTrucks = { 'scrap' }
Config.FluidTrucks = { 'scrap' }
Config.TruckData = {
['scrap'] = {
modelName = 'scrap',
}
}
Config.POI = {
['Beachfront Market'] = {
availableCargo = { 'Sand' }, -- things you can pick up here
acceptingCargo = { 'Old Junk' } -- things you can drop off here
}
}
Config.CargoTypes = {
['Old Junk'] = {
ValuePerKg = 0.2
}
}
This is what brings me to my question and makes me wonder how the server side files are actually being read/executed. Any insight on this would be great, thanks for reading!