• Help on odd lua error
    2 replies, posted
So this guy from ukraine is getting a error: [ERROR] ...art_welding/lua/weapons/gmod_tool/stools/smartwelder.lua:273: attempt to index local 'ent1' (a nil value) 1. unknown - ...art_welding/lua/weapons/gmod_tool/stools/smartwelder.lua:273 error It keep telling him its can be because he has over 100 addons on his server but he refuses to listen. That entire section of code is: [CODE]function TOOL:WeldEnts(ent1, ent2, bone1, bone2, weldstrength, smartnocollide, weldcount) if(ent1:IsValid() and ent2:IsValid()) then -- this is line 273 local const = constraint.Weld( ent1, ent2, bone1, bone2, weldstrength, smartnocollide ) undo.AddEntity( const ) if(((weldcount+1)%NOTIFYGAP)==0) then self:GetOwner():PrintMessage(HUD_PRINTCENTER,"Weld "..(weldcount+1).." placed") end end end [/CODE] The addon is smart weld. Could this error be because I screwed up fixing the addon for gmod 13. This is my first time scripting in lua so I'm not the greatest. So please help. Thanks
[QUOTE=YourStalker;38945059]So this guy from ukraine is getting a error: [ERROR] ...art_welding/lua/weapons/gmod_tool/stools/smartwelder.lua:273: attempt to index local 'ent1' (a nil value) 1. unknown - ...art_welding/lua/weapons/gmod_tool/stools/smartwelder.lua:273 error It keep telling him its can be because he has over 100 addons on his server but he refuses to listen. That entire section of code is: [CODE]function TOOL:WeldEnts(ent1, ent2, bone1, bone2, weldstrength, smartnocollide, weldcount) if(ent1:IsValid() and ent2:IsValid()) then -- this is line 273 local const = constraint.Weld( ent1, ent2, bone1, bone2, weldstrength, smartnocollide ) undo.AddEntity( const ) if(((weldcount+1)%NOTIFYGAP)==0) then self:GetOwner():PrintMessage(HUD_PRINTCENTER,"Weld "..(weldcount+1).." placed") end end end [/CODE] The addon is smart weld. Could this error be because I screwed up fixing the addon for gmod 13. This is my first time scripting in lua so I'm not the greatest. So please help. Thanks[/QUOTE] You're calling the function without ent1 or ent2. Add a check like [code] if ( ent1 and ent2 and IsValid(ent1) and IsValid(ent2) ) then [/code] That will prevent the error.
[QUOTE=Leystryku;38945170]You're calling the function without ent1 or ent2. Add a check like [code] if ( ent1 and ent2 and IsValid(ent1) and IsValid(ent2) ) then [/code] That will prevent the error.[/QUOTE] Why is that though. Was it just because it change from gmod 12 to 13. Oh and thank you very much I really appreciate it ill try it out [editline]23rd December 2012[/editline] That made it worse. Now the tool doesn't show
Sorry, you need to Log In to post a reply to this thread.