• 57: attempt to index field 'len' (a string value)
    34 replies, posted
Hi. Help me! PLS! What CMD means - (a string value)? include("shared.lua") surface.CreateFont("NameYourFont",{font = "Arial",extended = false,size = 50, weight = 500}) function ENT:Initialize()     self.len = {"text","ani","",""}     self.deni = 1     print(self.deni) end function ENT:Draw()     self:DrawModel()     local oang = self:GetAngles()          local ang1 = self:GetAngles()     local pos1 = self:GetPos()          ang1:RotateAroundAxis(oang:Up(), -270)     ang1:RotateAroundAxis(oang:Right(), 0)          pos1 = pos1 + oang:Forward() * -20 + oang:Up() * 2 + oang:Right() * 40          cam.Start3D2D(pos1,ang1,0.1)         draw.SimpleTextOutlined(self.len[1], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D()     cam.Start3D2D(pos1 + oang:Right() * -40,ang1,0.1)         draw.SimpleTextOutlined(self.len[2], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D()     net.Receive("SendDermaS",function()             local frame = vgui.Create("DFrame")             frame:SetSize(500,200)             frame:Center()             frame:SetVisible(true)             frame:MakePopup()             local NumberWang = vgui.Create("DNumberWang",frame)             NumberWang:SetPos(25,80)             NumberWang:SetEnterAllowed(true)             NumberWang:SetMax(15)             NumberWang:SetMin(1)             NumberWang:SetDecimals(self.deni)             function NumberWang:OnValueChanged()                 self.deni = NumberWang:GetValue()                 print(self.deni)             end             print(self.deni .. "main")             local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram             TextEntry:SetPos( 25, 50 )             TextEntry:SetSize( 85, 20 )             TextEntry:SetEnterAllowed(true)             TextEntry:SetText(self.len[self.deni])             TextEntry.OnEnter = function()                 self.deni = NumberWang:GetValue()                 print(self.deni .. " world")                 self.len[self.deni] = TextEntry:GetValue()                     print(self.len[1])             end     end) end 57 - self.len[self.deni] = TextEntry:GetValue() 
You shouldn't declare a net.Receive in an ENT:Draw - it will add a new receive hook every time the entity draws. Declare it outside of the entity and send the entity in the serverside net message.
Somewhere you're setting `self.len` to a string. It's not in the snippet you've posted. PS: Don't define a net.Receive in ENTITY/Draw, network the entity in the net message and set it on that. Secondly, your `function NumberWang:OnValueChanged()`is overwriting the local `self` variable, so that `self.deni = NumberWang:GetValue()` is actually setting it on the NumberWang, not the entity.
I only understood that I have to declare net outside.. but I don't know what I have to do with `self.deni` How my code looks: include("shared.lua") surface.CreateFont("NameYourFont",{font = "Arial",extended = false,size = 50, weight = 500}) function ENT:Initialize()     self.len = {"text","ani","",""}     self.deni = 1     print(self.deni) end net.Receive("SendDermaS",function()         local frame = vgui.Create("DFrame")         frame:SetSize(500,200)         frame:Center()         frame:SetVisible(true)         frame:MakePopup()                  local NumberWang = vgui.Create("DNumberWang",frame)         self.deni = NumberWang:GetValue()         NumberWang:SetPos(25,80)         NumberWang:SetEnterAllowed(true)         NumberWang:SetMax(15)         NumberWang:SetMin(1)         NumberWang:SetDecimals(self.deni)         print(self.deni)         print(self.deni .. "main")         local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram         TextEntry:SetPos( 25, 50 )         TextEntry:SetSize( 85, 20 )         TextEntry:SetEnterAllowed(true)         TextEntry:SetText(self.len[self.deni])         TextEntry.OnEnter = function()             self.deni = NumberWang:GetValue()             print(self.deni .. " world")             self.len[self.deni] = TextEntry:GetValue()                 print(self.len[1])         end end) function ENT:Draw()     self:DrawModel()     local oang = self:GetAngles()          local ang1 = self:GetAngles()     local pos1 = self:GetPos()          ang1:RotateAroundAxis(oang:Up(), -270)     ang1:RotateAroundAxis(oang:Right(), 0)          pos1 = pos1 + oang:Forward() * -20 + oang:Up() * 2 + oang:Right() * 40          cam.Start3D2D(pos1,ang1,0.1)         draw.SimpleTextOutlined(self.len[1], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D()     cam.Start3D2D(pos1 + oang:Right() * -40,ang1,0.1)         draw.SimpleTextOutlined(self.len[2], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D() end       
You aren't defining self in your net callback - you have to net.WriteEntity the entity you want to use serverside, then net.ReadEntity clientside in the callback.
I'm no expert, and I guess this is kinda a question if I'm wrong, but since ".len" is a part of the string library, is it trying to run ".len" on "self", expecting it to be "string" or of the same type instead and failing?
No `foo[1] = bar` In the above example Lua will attempt to look up the `__newindex` meta method for `foo`. If it doesn't have one and it's not a table then it'll error with "attempt to index global 'foo' (a typename value)". Only difference between my example and the problem in this thread is that it's a table field so it says "field" instead of "global".
-_- ERROR: 9: attempt to index global 'self' (a nil value) -  self.deni = net.ReadEntity() SERVER SIDE function ENT:AcceptInput( name, activator, caller )     if( !caller:IsValid() || !caller:IsPlayer() || name != "Use" ) then return end     net.Start('SendDermaS')     net.WriteEntity(self.denis)     net.Broadcast() end    CLIENT SIDE net.Receive("SendDermaS",function()         self.deni = net.ReadEntity()         local frame = vgui.Create("DFrame")         frame:SetSize(500,200)         frame:Center()         frame:SetVisible(true)         frame:MakePopup()                  local NumberWang = vgui.Create("DNumberWang",frame)         NumberWang:SetPos(25,80)         NumberWang:SetEnterAllowed(true)         NumberWang:SetMax(15)         NumberWang:SetMin(1)         NumberWang:SetDecimals(self.deni)         print(self.deni)         print(self.deni .. "main")         local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram         TextEntry:SetPos( 25, 50 )         TextEntry:SetSize( 85, 20 )         TextEntry:SetEnterAllowed(true)         TextEntry:SetText(self.len[self.deni])         TextEntry.OnEnter = function()             self.deni = NumberWang:GetValue()             print(self.deni .. " world")             self.len[self.deni] = TextEntry:GetValue()                 print(self.len[1])         end end)
I have not used 'self' much but im pretty sure in a net.Receive it is not able to be used so self.deni = net.ReadEntity() would not work as self does not exist, try setting the variable to something else like local local variableName = net.ReadEntity() since there is no point appending it to self when it is only called within that function.
Not self.deni, just self.
Aa? Yes, maybe I am a little bit dumb.. but I am just learning Error: attempt to concatenate field 'm_iDecimals' (a nil value) net.Receive("SendDermaS",function()         self = net.ReadEntity() ---?????         local frame = vgui.Create("DFrame")         frame:SetSize(500,200)         frame:Center()         frame:SetVisible(true)         frame:MakePopup()                  local NumberWang = vgui.Create("DNumberWang",frame)         NumberWang:SetPos(25,80)         NumberWang:SetEnterAllowed(true)         NumberWang:SetMax(15)         NumberWang:SetMin(1)         NumberWang:SetDecimals(self.deni)         print(self.deni)         print(self.deni .. "main")         local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram         TextEntry:SetPos( 25, 50 )         TextEntry:SetSize( 85, 20 )         TextEntry:SetEnterAllowed(true)         TextEntry:SetText(self.len[self.deni])         TextEntry.OnEnter = function()             self.deni = NumberWang:GetValue()             print(self.deni .. " world")             self.len[self.deni] = TextEntry:GetValue()                 print(self.len[1])         end end)
Can you post your serverside code? Also, make self a local variable.
What exactly are you trying to create? We can keep helping you fix errors but it would be better to know what you're trying to do and maybe offer a better solution.
CLIENT SIDE include("shared.lua") surface.CreateFont("NameYourFont",{font = "Arial",extended = false,size = 50, weight = 500}) function ENT:Initialize()     self.len = {"text","ani","",""} end net.Receive("SendDermaS",function()         self = net.ReadEntity()         local frame = vgui.Create("DFrame")         frame:SetSize(500,200)         frame:Center()         frame:SetVisible(true)         frame:MakePopup()                  local NumberWang = vgui.Create("DNumberWang",frame)         NumberWang:SetPos(25,80)         NumberWang:SetEnterAllowed(true)         NumberWang:SetMax(15)         NumberWang:SetMin(1)         NumberWang:SetDecimals(self.deni)         print(self.deni)         print(self.deni .. "main")         local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram         TextEntry:SetPos( 25, 50 )         TextEntry:SetSize( 85, 20 )         TextEntry:SetEnterAllowed(true)         TextEntry:SetText(self.len[self.deni])         TextEntry.OnEnter = function()             self.deni = NumberWang:GetValue()             print(self.deni .. " world")             self.len[self.deni] = TextEntry:GetValue()                 print(self.len[1])         end end) function ENT:Draw()     self:DrawModel()     local oang = self:GetAngles()          local ang1 = self:GetAngles()     local pos1 = self:GetPos()          ang1:RotateAroundAxis(oang:Up(), -270)     ang1:RotateAroundAxis(oang:Right(), 0)          pos1 = pos1 + oang:Forward() * -20 + oang:Up() * 2 + oang:Right() * 40          cam.Start3D2D(pos1,ang1,0.1)         draw.SimpleTextOutlined(self.len[1], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D()     cam.Start3D2D(pos1 + oang:Right() * -40,ang1,0.1)         draw.SimpleTextOutlined(self.len[2], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D() end         SERVER SIDE AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") util.AddNetworkString("SendDermaS") function ENT:Initialize()     self:SetModel("models/hunter/plates/plate1x2.mdl")     self:SetMaterial("models/rendertarget")     self:PhysicsInit(SOLID_VPHYSICS)     self:SetMoveType(MOVETYPE_VPHYSICS)     self:SetSolid(SOLID_VPHYSICS)     self:SetUseType(SIMPLE_USE)     self.isRunning = false     local phys = self:GetPhysicsObject()     if(phys:IsValid()) then         phys:Wake()     end     end function ENT:AcceptInput( name, activator, caller )     if( !caller:IsValid() || !caller:IsPlayer() || name != "Use" ) then return end     net.Start('SendDermaS')     net.WriteEntity(self.denis)     net.Broadcast() end    
You're still writing self.denis even though should be writing self. Also, again, make self a local variable clientside.
And what I have to do with this local variable? Error: 35: attempt to index global 'self' (a nil value) - TextEntry:SetText(self.len[deni]) SERVER SIDE AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") util.AddNetworkString("SendDermaS") function ENT:Initialize()     self:SetModel("models/hunter/plates/plate1x2.mdl")     self:SetMaterial("models/rendertarget")     self:PhysicsInit(SOLID_VPHYSICS)     self:SetMoveType(MOVETYPE_VPHYSICS)     self:SetSolid(SOLID_VPHYSICS)     self:SetUseType(SIMPLE_USE)     self.isRunning = false     local phys = self:GetPhysicsObject()     if(phys:IsValid()) then         phys:Wake()     end     end function ENT:AcceptInput( name, activator, caller )     if( !caller:IsValid() || !caller:IsPlayer() || name != "Use" ) then return end     net.Start('SendDermaS')     net.WriteEntity(self)     net.Broadcast() end     CLIENT SIDE include("shared.lua") surface.CreateFont("NameYourFont",{font = "Arial",extended = false,size = 50, weight = 500}) function ENT:Initialize()     self.len = {"text","ani","",""} end net.Receive("SendDermaS",function()         local deni = net.ReadEntity()         print(deni)         local frame = vgui.Create("DFrame")         frame:SetSize(500,200)         frame:Center()         frame:SetVisible(true)         frame:MakePopup()                  local NumberWang = vgui.Create("DNumberWang",frame)         deni = NumberWang:GetDecimals()         print(deni)         NumberWang:SetPos(25,80)         NumberWang:SetEnterAllowed(true)         NumberWang:SetMax(15)         NumberWang:SetMin(1)         NumberWang:SetDecimals(deni)         print(deni .. "main")         local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram         TextEntry:SetPos( 25, 50 )         TextEntry:SetSize( 85, 20 )         TextEntry:SetEnterAllowed(true)         TextEntry:SetText(self.len[deni])         TextEntry.OnEnter = function()             deni = NumberWang:GetValue()             print(deni .. " world")             self.len[deni] = TextEntry:GetValue()                 print(self.len[1])         end end) function ENT:Draw()     self:DrawModel()     local oang = self:GetAngles()          local ang1 = self:GetAngles()     local pos1 = self:GetPos()          ang1:RotateAroundAxis(oang:Up(), -270)     ang1:RotateAroundAxis(oang:Right(), 0)          pos1 = pos1 + oang:Forward() * -20 + oang:Up() * 2 + oang:Right() * 40          cam.Start3D2D(pos1,ang1,0.1)         draw.SimpleTextOutlined(self.len[1], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D()     cam.Start3D2D(pos1 + oang:Right() * -40,ang1,0.1)         draw.SimpleTextOutlined(self.len[2], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D() end       
Why did you rename the self variable to deni?
You said: You have to create local variable. And what I have to do with it? Sit and watch in monitor? XD I guess I have to use this variable
I meant keep the previous variable name "self" but make it local - not change it to deni.
Like that =( ? And what next net.Receive("SendDermaS",function()         local self = net.ReadEntity()         print(deni)         local frame = vgui.Create("DFrame")         frame:SetSize(500,200)         frame:Center()         frame:SetVisible(true)         frame:MakePopup()                  local NumberWang = vgui.Create("DNumberWang",frame)         NumberWang:SetPos(25,80)         NumberWang:SetEnterAllowed(true)         NumberWang:SetMax(15)         NumberWang:SetMin(1)         NumberWang:SetDecimals(self.deni)         print(self.deni)         print(self.deni .. "main")         local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram         TextEntry:SetPos( 25, 50 )         TextEntry:SetSize( 85, 20 )         TextEntry:SetEnterAllowed(true)         TextEntry:SetText(self.len[self.deni])         TextEntry.OnEnter = function()             self.deni = NumberWang:GetValue()             print(self.deni .. " world")             self.len[self.deni] = TextEntry:GetValue()                 print(self.len[1])         end end)
Looks fine with your previous entity code - what's the issue?
attempt to concatenate field 'm_iDecimals' (a nil value) cl_init.lua:24 CL SIDE include("shared.lua") surface.CreateFont("NameYourFont",{font = "Arial",extended = false,size = 50, weight = 500}) function ENT:Initialize()     self.len = {"text","ani","",""} end net.Receive("SendDermaS",function()         local self = net.ReadEntity()         print(deni)         local frame = vgui.Create("DFrame")         frame:SetSize(500,200)         frame:Center()         frame:SetVisible(true)         frame:MakePopup()                  local NumberWang = vgui.Create("DNumberWang",frame)         NumberWang:SetPos(25,80)         NumberWang:SetEnterAllowed(true)         NumberWang:SetMax(15)         NumberWang:SetMin(1)             NumberWang:SetDecimals(self.deni)         print(self.deni)         print(self.deni .. "main")         local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of fram         TextEntry:SetPos( 25, 50 )         TextEntry:SetSize( 85, 20 )         TextEntry:SetEnterAllowed(true)         TextEntry:SetText(self.len[self.deni])         TextEntry.OnEnter = function()             self.deni = NumberWang:GetValue()             print(self.deni .. " world")             self.len[self.deni] = TextEntry:GetValue()                 print(self.len[1])         end end) function ENT:Draw()     self:DrawModel()     local oang = self:GetAngles()          local ang1 = self:GetAngles()     local pos1 = self:GetPos()          ang1:RotateAroundAxis(oang:Up(), -270)     ang1:RotateAroundAxis(oang:Right(), 0)          pos1 = pos1 + oang:Forward() * -20 + oang:Up() * 2 + oang:Right() * 40          cam.Start3D2D(pos1,ang1,0.1)         draw.SimpleTextOutlined(self.len[1], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D()     cam.Start3D2D(pos1 + oang:Right() * -40,ang1,0.1)         draw.SimpleTextOutlined(self.len[2], 'NameYourFont', 0,0,Color(255,255,255), TEXT_ALIGN_LEFT ,TEXT_ALIGN_TOP,1,Color(0,0,0,alpha))     cam.End3D2D() end        SV SIDE AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") util.AddNetworkString("SendDermaS") function ENT:Initialize()     self:SetModel("models/hunter/plates/plate1x2.mdl")     self:SetMaterial("models/rendertarget")     self:PhysicsInit(SOLID_VPHYSICS)     self:SetMoveType(MOVETYPE_VPHYSICS)     self:SetSolid(SOLID_VPHYSICS)     self:SetUseType(SIMPLE_USE)     self.isRunning = false     local phys = self:GetPhysicsObject()     if(phys:IsValid()) then         phys:Wake()     end     end function ENT:AcceptInput( name, activator, caller )     if( !caller:IsValid() || !caller:IsPlayer() || name != "Use" ) then return end     net.Start('SendDermaS')     net.WriteEntity(self)     net.Broadcast() end    
You are calling NumberWang:SetDecimals(self.deni) before you define self.deni - maybe you should define it to 1 by default in your ENT:Initialize?
Wow! Much better! But when I press Enter to change text CMD says: attempt to index global 'NumberWang' (a nil value) :27: - self.deni = NumberWang:GetValue()
Because "self" refers to the entity read off the netstream - you can't access the entity until you've stored it into a variable, hence local self.
I made small test and when I change value of the NumberWang print spams about twenty times https://files.facepunch.com/forum/upload/157971/c15e482e-16f9-4421-a9ec-f9259671d808/изображение.png
Maybe you should store your frame and numberwang to the (self.frame, etc.) entity and check if one exists before creating a new one.
 Error:attempt to index field 'TextEntry' (a nil value) function self.NumberWang:OnValueChanged(val)                 if !( IsValid(entity ) ) then                 self.TextEntry:SetText(self.len[val])             end         end
You have to put an actual variable in the IsValid parenthesis - entity is nil. Also, think about your code logically: if an entity is NOT VALID, run this code. Seems backwards.
Too hard... actual variable of what?
Sorry, you need to Log In to post a reply to this thread.