Nill value?


if ply:IsPlayer() then
    ragdoll = ents.Create("prop_ragdoll")
	ragdoll:SetHealth(100)
	ragdoll:SetPos( ply:GetPos() )
	ragdoll:SetModel(ply:GetModel())
	ragdoll:Spawn()
	ragdoll:Activate()
	ragdoll.Owner = ply
	ragdoll.name = ply:Name()
	ragdoll:GetPhysicsObject():SetVelocity(ply:GetPhysicsObject():GetVelocity())
	
	print( "This is "..ragdoll.name.."")
	
	ply:Spectate(OBS_MODE_IN_EYE)
	ply:SpectateEntity(ragdoll)
	ply.IsUnconc = true
	ply.KunitsRagdoll = ragdoll
	ply.TheName = ragdoll.name
	ply.PriorDeathJob = ply:Team()


For some reason when I try to do this:


 local Form = vgui.Create( "DFrame" )
		Form:SetPos( ScrW()/2 - 250,ScrH()/2 - 100 ) 
		Form:SetSize( 500, 100 ) 
		Form:SetTitle("Examining ".. name.."'s body") 
		Form:SetVisible( true ) 
		Form:SetDraggable( true ) 
		Form:ShowCloseButton( true ) 
		Form:MakePopup() 

name returns nill/null. I cant figure out why. name is defined in the other function and when I print it, It prints the name. Why is it not working here?
Help please?

Because you are accessing it via ‘name’, not ‘ragdoll.name’.

also, vgui.Create is clientside, ents.Create is serverside, so, you’ll need to network

ragdoll returns nill because its in another function. I tried KunitsRagdoll.name and ply.KunitsRagdoll.name and KunitsRagdoll returns nill.

[editline]26th September 2014[/editline]

Its working perfectly so…, well the derma panel anyway. Only error is the name.

I’m clueless ATM no any help is appreciated

well you still have to do networking, or use SetNWEntity, because youre setting a variable on the player on serverside and trying to access it on clientside code

Oh shit. So the problem is the serverside value wont work on client-side. Shit thanks. What would I change the ragdoll.name to? Sorry Ive just never had to do this before.

you need to set a variable that will hold it. just set a nw string or whatever.

Could I have an example please?

You network it.

Add this to the clientside file with the formmenu and replace “functionname” with the menus function name
[lua]net.Receive(“theformmenu”, functionname)
[/lua]

Then add this to the code where you set the ragdoll name
[lua]
net.Start(“theformmenu”)
net.WriteString(ragdoll.name)
net.Send(ply)
[/lua]

And then add this to the menu function
[lua]local ragdollname = net.ReadString()
[/lua]

And add this to a serverside file.
[lua]util.AddNetworkString(“theformmenu”)[/lua]

Example
a shared lua file


if SERVER then 

util.AddNetworkString("theformmenu")
function something(ply)
	if ply:IsPlayer() then
    ragdoll = ents.Create("prop_ragdoll")
	ragdoll:SetHealth(100)
	ragdoll:SetPos( ply:GetPos() )
	ragdoll:SetModel(ply:GetModel())
	ragdoll:Spawn()
	ragdoll:Activate()
	ragdoll.Owner = ply
	ragdoll.name = ply:Name()
	ragdoll:GetPhysicsObject():SetVelocity(ply:GetPhysicsObject():GetVelocity())
	
	print( "This is "..ragdoll.name.."")
	
	ply:Spectate(OBS_MODE_IN_EYE)
	ply:SpectateEntity(ragdoll)
	ply.IsUnconc = true
	ply.KunitsRagdoll = ragdoll
	ply.TheName = ragdoll.name
	ply.PriorDeathJob = ply:Team()
	
	net.Start("theformmenu")
	   net.WriteString(ragdoll.name)
    net.Send(ply)

end

end


if CLIENT then

function formmenu()
local ragdollname = net.ReadString()

  local dermal = vgui.Create("DFrame")
  dermal:SetSize(1000, 800)
  dermal:SetTitle(ragdollname)
  dermal:SetVisible(true)
  dermal:SetDraggable( true ) 
  dermal:ShowCloseButton( true )
  dermal:MakePopup()
  dermal:Center()
   
 
end
net.Receive("theformmenu", formmenu) 

end

forgot many things
parenthesies on net.SendToServer()
it isnt supposed to be SendToServer because hes sending info to the client (so just net.Send()
the util. at the start of the AddNetworkString function
‘recieve’ is spelt receive

Thanks! I will try this out in a bit. Thanks so much, I haven’t tested it yet but I can tell it will work. :smiley:

[editline]26th September 2014[/editline]

Thanks for correcting that. I’ll make sure to add your corrections.

Yeah I know that net.SendToServer is client to server. And thanks for the corrections :smiley:

[editline]26th September 2014[/editline]

I’ve updated my post and added an example. It should work but if you get any errors just post them

Yeah I will. I have to go for a bit so I won’t reply for a while but I’ll definitely update the post if all is good. Thanks anyway. Have a nice day.

Sorry for kind of derailing the thread, but it’s nil, not nill. :v:

Unless nill was assigned a value, it too is nil, just like many variable names.


print( nill, " == ", type( nill ) );

== nil


GameMode loaded 743 files!


[AcecoolDev]-GameMode Refreshed. You’ve been here for [09:25:55].

But, still… You’d be right by saying nil is the protected key-word and the only thing that should be used to test for nil, or to nullify elements.

It says its still nil. I put in everything you said…

NEVER MIND! it works! Thanks to everyone who helped. I’ll mark this as solved ^^