• Help with Data tables and networkVar
    3 replies, posted
I am running into issues using networked variables and the wiki isnt being much help. My goal is to have a boolean value that I can change. This one runs without lua errors but when I do "GetCanDropAmmo" it always returns false no matter what number I put in there [code] function ENT:SetupDataTables() self:NetworkVar( "Bool", 1, "CanDropAmmo") end [/code] And this gives me a lua error [code] function ENT:SetupDataTables() self:NetworkVar( "Bool", true, "CanDropAmmo") end [/code] [quote] use [ERROR] lua/includes/extensions/entity.lua:289: bad argument #2 to '__index' (number expected, got boolean) 1. __index - [C]:-1 2. GetCanDropAmmo - lua/includes/extensions/entity.lua:289 3. GiveAmmo - addons/ttt weps/lua/entities/ttt_briefcase.lua:77 4. unknown - addons/ttt weps/lua/entities/ttt_briefcase.lua:97 [/quote] Where line 77 is " local CanAmmo = self:GetCanDropAmmo() " and 97 is the my custom function under ENT:Use.
second argument must be a number, it means the ID of the networkvar, not default value.
You're meant to set up the NetworkVar so that you can set the value later, probably in ENT:Initialize(), using self:SetCanDropAmmo( true ), ENT:SetupDataTables() is only for creating the NetworkVars.
[QUOTE=Internet1001;45113790]You're meant to set up the NetworkVar so that you can set the value later, probably in ENT:Initialize(), using self:SetCanDropAmmo( true ), ENT:SetupDataTables() is only for creating the NetworkVars.[/QUOTE] Thanks both of you [code] [function ENT:SetupDataTables() self:NetworkVar( "Bool", 1, "AmmoCanDrop") self:SetAmmoCanDrop( true ) end [/code]
Sorry, you need to Log In to post a reply to this thread.