Hello, recently I started a thread on how to receive files from data folder.
I was trying to add DarkRP jobs, and now everything works but, the creating job part!
[CODE]AddCSLuaFile()
local locations = {}
function INITIALIZE()
local files, directories = file.Find( "the-creator-logs/jobs/*", "DATA" )
for k,v in pairs( directories ) do
table.insert( locations, "the-creator-logs/jobs/"..v )
end
for k,v in pairs( locations ) do
LocalPlayer():ChatPrint( "Salary for "..directories[k].." "..file.Read( v.."/salary.txt", "DATA" ) )
LocalPlayer():ChatPrint( "Category for "..directories[k].." "..file.Read( v.."/category.txt", "DATA" ) )
-- Jobs
TEAM_..string.upper( directiories[k] ) = DarkRP.createJob(directories[k], {
color = Color(255, 255, 255, 255),
model = {
"models/player/Group03/Female_01.mdl",
"models/player/Group03/Female_02.mdl"
},
description = [[This text will serve as the description of this team.]],
weapons = {"weapon_p2282"},
command = "godley",
max = 5, -- at most 70% of the players can have this job. Set to a whole number to set an absolute limit.
salary = tostring(file.Read( v.."/salary.txt", "DATA" )),
admin = 0,
vote = false,
hasLicense = false,
ammo = {
["pistol"] = 60,
},
category = tostring(file.Read( v.."/category.txt", "DATA" )), -- The name of the category it is in. Note: the category must be created!
})
end
end
hook.Add( "Initialize", "Initialize", INITIALIZE )[/CODE]
Now if I have this outside of hook.Add it loads BUT, it cant have the names I want it too have.
Example: TEAM_..string.upper( directiories[k] ) = DarkRP.createJob(directories[k]. Directories is from the local up top and [k] is the file number of the k,v. Anyway, I wan't to create a job for every single file found. It works, without the darkrp add job. Anyway I can go around this? And I am trying to make a table called: TEAM_(directoryname) but it errors. Maybe thats my probleM?
Thats not how programming language works...
TEAM_ its not a string, its a var object, you cant concatenate variables as it, you got the idea but you took the worst way to implement it
[QUOTE=gonzalolog;51389621]Thats not how programming language works...
TEAM_ its not a string, its a var object, you cant concatenate variables as it, you got the idea but you took the worst way to implement it[/QUOTE]
I could be wrong here, but I think this solves that problem:
[lua]
_G["TEAM_" .. string.upper( directiories[k] )]
[/lua]
[QUOTE=Skere_;51390233]I could be wrong here, but I think this solves that problem:
[lua]
_G["TEAM_" .. string.upper( directiories[k] )]
[/lua][/QUOTE]
A bit of a hacky solution, but really, it should be done with team.GetName or the job name.
[QUOTE=Skere_;51390233]I could be wrong here, but I think this solves that problem:
[lua]
_G["TEAM_" .. string.upper( directiories[k] )]
[/lua][/QUOTE]
Quick question, whats with _G? because DarkRP TEAM_(name) not _GTEAM_(Name)
[QUOTE=jacobcooper18;51390273]Quick question, whats with _G? because DarkRP TEAM_(name) not _GTEAM_(Name)[/QUOTE]
_G is the global table Lua stores everything in by default. TEAM_ enums are globals stored in _G. Again, you should look into using team.GetName or using the job name.
But whats the point of that, like why would do you define a variable that later you cant access with other hacky methods, what about if you just do a global table containing those jobs with the folder name as indexes so you can really access at them
This just will bring more problems than solutions
A bit unrelated but you should localize INITIALIZE() since you probably only made it for the hook.
And to explain this:
[QUOTE=jacobcooper18;51390273]Quick question, whats with _G? because DarkRP TEAM_(name) not _GTEAM_(Name)[/QUOTE]
_G is the global table where the shizzle is stored as code_gs said, where the indexes are the variable names.
Some examples with their alternatives
[lua]
print( "test1" )
_G["print"]( "test1" )
mymoney = 500
_G["my" .. "money"] = 500
[/lua]
Its pretty useful for using variables inside variable names, though you should probably go for code_gs' solution.
[QUOTE=gonzalolog;51390996]But whats the point of that, like why would do you define a variable that later you cant access with other hacky methods, what about if you just do a global table containing those jobs with the folder name as indexes so you can really access at them
This just will bring more problems than solutions[/QUOTE]
Yes, but that will ruin the purpose. And aswell, I have tried that, thats why the solutions are hacky.
[editline]19th November 2016[/editline]
[QUOTE=Skere_;51391019]A bit unrelated but you should localize INITIALIZE() since you probably only made it for the hook.
And to explain this:
_G is the global table where the shizzle is stored as code_gs said, where the indexes are the variable names.
Some examples with their alternatives
[lua]
print( "test1" )
_G["print"]( "test1" )
mymoney = 500
_G["my" .. "money"] = 500
[/lua]
Its pretty useful for using variables inside variable names, though you should probably go for code_gs' solution.[/QUOTE]
I will, but lol. Concatonating a string? Makes no sense man. "".."" that will not work, it should be more: "my money"... xD
Nice try though.
[QUOTE=jacobcooper18;51392269]
I will, but lol. Concatonating a string? Makes no sense man. "".."" that will not work, it should be more: "my money"... xD
Nice try though.[/QUOTE]
What? Concentrating is connecting multiple strings, so saying that makes no sense is a bit silly. And I just gave the example because it was relevant to your problem, and to portrait the difference to defining a variable normally.
And there is no space because variable names can't contain spaces
Sorry, you need to Log In to post a reply to this thread.