I'm trying to make a call of duty FPS type game and this is for the class but I'm not really good at tables and when I try this the output comes out as nil. Any help would be appreciated.
local class1 = { Primary = "AN-94"; PrimaryAttachments = "Reflex Sight"; PrimaryAttachments2 = "Laser Sight"; PrimaryAttachments3 = "Quickdraw"; Secondary = "M1911"; equipment = "Frag Grenade"; tactical = "Tactical Insertion"; Perk1 = "Sleight of Hand"; Perk2 = "Lighweight"; Perk3 = "Dead Silence" } local class2 = { Primary = "SCAR-L"; Secondary = "M1911"; equipment = "Frag Grenade"; tactical = "Tactical Insertion"; Perk1 = "Sleight of Hand"; Perk2 = "Lighweight"; Perk3 = "Dead Silence" } local activeclass = class1 print(class1[2])
The reason it comes out as nil is you have altered the index.
Here is an example of what I'm talking about
local Tab = {NewIndexName = 'This is a string value', TestIndex = 2, ['Hacked Index'] = math.pi} for Index, Value in pairs (Tab) do print('Index: '..Index..; Value: '..Value) end
If you wanted to print the value, you have to access it by it's index, so if you have changed the index from numbers to a string value then you have to use the new string value you set on the value
local Tab = {NewIndexName = 'This is a string value', TestIndex = 2, ['Hacked Index'] = math.pi} print(Tab['NewIndexName']) -- this will work for all cases print(Tab.TestIndex) --[[ or alternatively you could use this, although this may not work for all cases, such as the 'Hacked Index' since there is a space and the way you are retrieving the value in the table is not a string value )which you cannot use a space when you are not using a string, it will through you an error in the output) ]]