Alright, so I'm making this question npc thingy, but i keep getting this error. It obviously has to do with serverside/clientside, but i cannot quite figure it out. Could anyone please help?
[code]
local TextEntry = vgui.Create( "DTextEntry", Frame )
TextEntry:SetPos( 65, 49 )
TextEntry:SetSize( 75, 25 )
TextEntry:SetText( "Yes/No" )
TextEntry.OnEnter = function( self, ply )
if self:GetValue() == "Yes" then
chat.AddText("Correct!")
ply:SetNWBool( "question1_true", true)
else
chat.AddText("Wrong!")
end
[/code]
Error:
[code]
attempt to index local 'ply' (a nil value)
[/code]
Thanks for your help.
Just use LocalPlayer()
[QUOTE=RealDope;48276661]Just use LocalPlayer()[/QUOTE]
Then what do i do if i want to read the NWBool using GetNWBool serverside? That just returns "LocalPlayer() a nil value"
[QUOTE=SkitZz;48276693]Then what do i do if i want to read the NWBool using GetNWBool serverside? That just returns "LocalPlayer() a nil value"[/QUOTE]
Depending on what function you are calling it on serverside, you use ply generally for serverside and LocalPlayer for client side.
[QUOTE=Mrkrabz;48276731]Depending on what function you are calling it on serverside, you use ply generally for serverside and LocalPlayer for client side.[/QUOTE]
Alright, so i did this clientside:
[code]
local TextEntry = vgui.Create( "DTextEntry", Frame )
TextEntry:SetPos( 65, 49 )
TextEntry:SetSize( 75, 25 )
TextEntry:SetText( "Yes/No" )
TextEntry.OnEnter = function( self, ply )
if self:GetValue() == "Yes" then
chat.AddText("Correct!")
LocalPlayer():SetNWBool( "question1", true)
else
chat.AddText("Wrong!")
end
[/code]
But when i try and get the NWBool serverside, it just returns false no matter what:
[code]
function AddStaff(ply)
print(ply:GetNWBool("question1"))
end
concommand.Add( "BoolTest", AddStaff )
[/code]
What could i be doing wrong?
SetNW* functions on client DON'T send changes to server. You'll have to use netmessages probably.
-snip I'm dumb-
[QUOTE=mijyuoon;48276828]SetNW* functions on client DON'T send changes to server. You'll have to use netmessages probably.[/QUOTE]
Yeah, so i tried that:
[code]
local TextEntry = vgui.Create( "DTextEntry", Frame )
TextEntry:SetPos( 65, 49 )
TextEntry:SetSize( 75, 25 )
TextEntry:SetText( "Yes/No" )
TextEntry.OnEnter = function( self, ply )
if self:GetValue() == "Yes" then
chat.AddText("Correct!")
net.Start("question_1", false)
net.SendToServer()
else
chat.AddText("Wrong!")
end
[/code]
I keep getting
[code]
Calling net.Start with unpooled message name! [http://goo.gl/qcx0y]
[/code]
Never mind, i found out why. I forgot to add [code]util.AddNetworkString( "question_1" ) [/code]
[DEL]You must pool the message name. [url]http://wiki.garrysmod.com/page/util/AddNetworkString[/url][/DEL]
got ninja'd by an edit
[QUOTE=SkitZz;48276848]-snip-[/QUOTE]
-snip, Late again-
:snip: Ninja'd.
3 people all trying to rectify one error that could've been prematurely solved by simply following the link given in the error -.-
[QUOTE=Chimpanzee;48276876]3 people all trying to rectify one error that could've been prematurely solved by simply following the link given in the error -.-[/QUOTE]
How would i go about reading that NWBool then?
I tried doing this serverside:
[code]
function GetInfo(pl)
print(pl:GetNWBool("question_1_correct"))
end
concommand.Add("Question_Answer", GetInfo)
[/code]
It just always returns false.
Edit: Found out why :P
Sorry, you need to Log In to post a reply to this thread.