• Why would it be nil?
    5 replies, posted
Just a quick question: If you define a variable in code and try to run it but get an error saying that it is nil, why is it nil if already defined? Also why would variables in predefined libraries be nil as well? (Keep in mind I'm not saying that it's nil every time, just in those occurrences where they are.) [CODE]-- Example local ply = LocalPlayer() --but when run you get ERROR: 'ply' is not defined --shitty example but you get the point[/CODE]
The engine has a small delay for the creation of the local player.
LocalPlayer can be nil if joining a server. You can use [url]http://samuelmaddock.github.io/glua-docs/#GM.InitPostEntity[/url] to wait til LocalPlayer is valid.
edit
Well I'm not talking just about LocalPlayer() that's just an example. I've had a few times where other variables were nil as well. Could it be that they aren't being set properly? (LocalPlayer was just off the top of my head)
Variables in lua are references. So when you do local x = something, then 'something' becomes nil, x will be nil also.
Sorry, you need to Log In to post a reply to this thread.