Jump to content

"attempt to index field 'darkvision' (a nil value)" problem


Recommended Posts

Hello! I wanted to make a character that would have the same night vision system like Charlie mod. I don't really know a lot about programming so I was looking into different mods and picking out some parts of codes. At first everything was fine, I solved every problem I could, but in the end I don't know how to solve this one: "[string ".../scripts/perfabs/alek.lua"]:129: attempt to index field 'darkvision' (a nil value)"

I've looked into line 129 and this is what I've got:

1463869831_(2449).png.90c16707609623612e67be70ff1328e5.png

I don't understand what's the problem and how to solve it, so can anybody explain what I can do about it and why something like this happend? Thanks!

 

Edited by JiRo.0
Link to comment
Share on other sites

local function applydarkvision(inst)
	if inst.components.playervision then
		if inst.darkvision:value() then
			inst.components.playervision:ForceNightVision(true)
		else
			inst.components.playervision:ForceNightVision(false)
		end
	end
end

local function registerdarkvisionlistener(inst)
	inst:ListenForEvent("darkvisiondirty", applydarkvision)
end

local function initializedarkvision(inst)
	inst.darkvision = net_bool(inst.GUID, "player.darkvision", "darkvisiondirty")
	inst.darkvision:set(false)
	inst:DoTaskInTime(0, registerdarkvisionlistener)
end

local common_postinit = function(inst)
initializedarkvision(inst)
-- Minimap icon
	inst.MiniMapEntity:SetIcon( "charlie.tex" )
inst:AddTag("charlie")
end

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...