• calling field "send" is a nill value?
    18 replies, posted
so I have this swep which works perfectly fine on SP but not on servers or on 2 player? [CODE]function SWEP:PrimaryAttack() net.Start("LeftClickedF") net.WriteBool(fsttimeclicked) fsttimeclicked = not fsttimeclicked net.Send(self:GetOwner()) // this is the line end [/CODE] I get this error and I cant figure out why (code doesnt work too in multiplayer) [CODE][ERROR] addons/rockford_swep/lua/weapons/rockford_map/shared.lua:25: attempt to call field 'Send' (a nil value) 1. unknown - addons/rockford_swep/lua/weapons/rockford_map/shared.lua:25 [/CODE] please help i am lost
net.Send is a serverside function and you're calling it in a shared function.
Your PrimaryAttack function should still be shared, but you should use a SERVER check to make your net code only run serverside. Also, use a class variable instead of global/local for fsttimeclicked
[QUOTE=txike;52802724]net.Send is a serverside function and you're calling it in a shared function.[/QUOTE][CODE]function SWEP:PrimaryAttack() if SERVER then net.Start("LeftClickedF") net.WriteBool(fsttimeclicked) fsttimeclicked = not fsttimeclicked net.Send(self:GetOwner()) end end[/CODE] This didnt fix it tough? And I cant put a shared function inside init ?
[QUOTE=Shendow;52802859]Are you getting the same error? Perhaps that function (minus the if SERVER part) has been copied in cl_init.lua.[/QUOTE] I am not getting any error now, but it doesnt work. I recieve the net message in cl_init thats all
[QUOTE=thejjokerr;52802894]That's what your code is supposed to do right? If there's something else broken as well show us that part.[/QUOTE] img snipped i dont really think anything is wrong in there, it only fails at shared.lua's part EDIT: img snipped
Can you post your init code?
[QUOTE=code_gs;52803047]Can you post your init code?[/QUOTE] [IMG]https://i.gyazo.com/062d39ea32e4eff91b323a56909e3096.png[/IMG] everything seems right to me :l
Also, fsttimeclicked is going to conflict between weapon instances unless you make it a class variable.
[QUOTE=Shendow;52804666]Can you actually describe what happens when you try clicking? Have you added print checks to see if: 1. the net message is actually being sent by the server 2. fsttimeclicked is true or false 3. the net message is actually being received by the client 4. the received boolean is what you expect For now you're being incredibly vague almost like you expect us to test and fix the code for you. We can't help you if you don't put the effort of trying things yourself and seeing what may be wrong. With the print checks I mentioned above you can see at which point your script doesn't work, and from there you can try stuff to fix your issue.[/QUOTE] No honestly not, I talked to code_gs on discord and told him what the swep is supposed to do on CLICKing it, basically on primary attack it opens a derma, and pressing it again removes it I dont expect anyone to test or fix the code I just want to know where I made my mistakes and why it was one [editline]21st October 2017[/editline] [QUOTE=code_gs;52804686]Also, fsttimeclicked is going to conflict between weapon instances unless you make it a class variable.[/QUOTE] Still dont quite grasp how to put it as a class variable self:GetOwner().fsttimeclicked or SWEP.fsttimeclicked?
Don't network a bool at all - just tell the client to toggle the image state.
[QUOTE=code_gs;52804733]Don't network a bool at all - just tell the client to toggle the image state.[/QUOTE] How do I do that tho? I cant send nothing I suppose so a bool is literally the next best thing for me
[QUOTE=MGFear;52805023]I cant send nothing[/QUOTE] [CODE]net.Start("messagename") net.Broadcast()[/CODE]
[QUOTE=thejjokerr;52805034]Send no content. Just the net message. net.Receive it at the client and toggle the menu Just receiving the message is enough. Needs to be no content.[/QUOTE] oh! thanks, you guys helped me a bunch and I think I got it to work correctly now/
Sorry, you need to Log In to post a reply to this thread.