Table error

Any idea where I’ve gone wrong in this table?



--Table layout

--Job Layout
CWRP_Jobs["Chief"] = {
JobName = "Police Chief",
JobSalary = 55,
JobTeam = "TEAM_CHIEF",
JobModel = "models/humans/nypd1940/male_07.mdl",
JobDesc = "The Police Chief is in charge of the entire Police Department.",
}


CWRP_Employers["Police"] = {
Employer = "Law Enforcement",
Model = "models/ai/policeofficers/npc_cop_07.mdl",
-----------------------------
Jobs = {
CWRP_Jobs["Police"],
CWRP_Jobs["Traffic"],
CWRP_Jobs["Chief"]
},
--Getting Job
CitizenTalk = "Hello Citizen",
OtherTalk = "Fuck off",
--Got Job
QuitTalk = "Wanna quit pal?",
---------
vec = Vector(-348.570557, -307.885071, -12223.968750),
ang = Angle(4.409999, 58.300583, 0.000000)
}


And I tried to do



PrintTable(CWRP_Employers.Jobs[k])


Result was:

JobTeam = TEAM_POLICE
JobSalary = 25
JobModel = models/player/nypd/cop_07.mdl

With no number index.

If I do:



PrintTable(CWRP_Employers.Jobs) 


It gives a number index. Any idea of how Im gonna get the number index by using [k] since I sorta need to do it that way.

[lua]CWRP_Jobs[“Chief”] = {
{JobName = “Police Chief”},
{JobSalary = 55},
– etc
}[/lua]

Can’t think of anything else you can do than this?

Ok testing it that way, gimme 1 min

[editline]28th February 2015[/editline]

EDIT: so wait, how would I fetch them clientside? Its no longer v.blah

CWRP_Jobs[1][1].JobName
CWRP_Jobs[1][2].JobSalary

yes this is a very bad way to do things, cant really think of what I did in this situation, probably some other stupid shit. Just try to think logics in your head, how you would be able to do what you want a little differently

As per Steam ( since the file was in reverse order ):

Tabs help: http://pastebin.com/eRdfx1te


--The job table layout within the NPC Table
CWRP_Jobs["Chief"] = {
	JobName = "Police Chief",
	JobSalary = 55,
	JobTeam = "TEAM_CHIEF",
	JobModel = "models/humans/nypd1940/male_07.mdl",
	JobDesc = "The Police Chief is in charge of the entire Police Department.",
	Locked = true,
	---------------------
	PreJob = true,
	ReqJob = "Police",
	PreJobText = "Police Officer"
}


---NPC Table. We send this to the client
CWRP_Employers["Police"] = {
	Employer = "Law Enforcement",
	Model = "models/ai/policeofficers/npc_cop_07.mdl",

	
	Jobs = {
		CWRP_Jobs["Police"],
		CWRP_Jobs["Traffic"],
		CWRP_Jobs["Chief"]
	},
	
	--Getting Job
	CitizenTalk = "Hello Citizen",
	OtherTalk = "Fuck off",
	--Got Job
	QuitTalk = "Wanna quit pal?",
	---------
	vec = Vector(-348.570557, -307.885071, -12223.968750),
	ang = Angle(4.409999, 58.300583, 0.000000)
}

Give your NPC an ID, such as Police, then you’d do


for k, v in pairs( CWRP_Employers.Police.Jobs ) do
    -- v.JobName, v.JobSalary, etc... -- add each job ( k ) to your vgui / list
end


With an id on your NPC:


for k, v in pairs( CWRP_Employers[ self.NPC_ID ]Jobs ) do
    -- v.JobName, v.JobSalary, etc... -- add each job ( k ) to your vgui / list
end


ie on Initialize, or in a shared file for your npc… Set ENT.NPC_ID = “Police”;

Also, you may want to just have the jobs table be shared instead of sending tables to client, etc… Saves on networking on join.

Thanks. Sorted it :smiley: