[Pointshop] Problem with getting Values from Tables (And use them for the Item Properties)

So I’ve worked on a code today to universally get all Info for a Pointshop Item based on just the Item Name/Item ID

Item ID= weapon_ttt_m16_ps


local entityname							= string.gsub(ITEM.ID, "_ps", "")

ITEM.Name									= ((weapons.GetStored(entityname)).PrintName)
ITEM.Price 									= 200
ITEM.Material 								= ((weapons.GetStored(entityname)).Icon)
ITEM.WeaponClass 							= entityname
ITEM.SingleUse 								= false

--(There is more Code to this Item but it is irrelevant)


(ERROR CODE BELOW)

But apparently


((weapons.GetStored(entityname)).PrintName)

Only works in a (?) Called function like this


concommand.Add( "testingcomand", function()
	print((weapons.GetStored("weapon_ttt_m16")).PrintName)
end )

>>Outputs: M16

Or


function ITEM:OnBuy(ply)
print((weapons.GetStored("weapon_ttt_m16")).PrintName)
end

>>Outputs: M16

Why is that? And how can I fix that? I really am lost on this one, because I was and still am sure that it should work… But it doesnt ._.

Greetings, Santifocus



[ERROR] lua/pointshop/items/mg/weapon_ttt_m16_ps.lua:3: attempt to index a nil value
  1. unknown - lua/pointshop/items/mg/weapon_ttt_m16_ps.lua:3
   2. include - [C]:-1
    3. LoadItems - lua/pointshop/sh_init.lua:119
     4. Initialize - lua/pointshop/sh_init.lua:54
      5. unknown - lua/autorun/pointshop.lua:3


The Pointshop file is being loaded before the M16 weapon file, so “weapon_ttt_m16” doesn’t exist yet.

Oh wow I did not know that, that makes quite a lote sense then ^^

Imma try something… brb
(timer.Simple)

[editline]30th October 2017[/editline]

Okay puttin timer.Simple(5, infront of function PS:LoadItems()


timer.Simple(5,function PS:LoadItems()

Just causes way more erros, figures.
Is there a way to delay the loading of the pointshop?

Your

timer.Simple is wrong


timer.Simple(5,function()
    PS:LoadItems()
end)

Yeah probably but that does not work either :confused:

Alrigth, found a solution myself …