attempt to index local/global function/nill value

FIXED*

NOT FIXED* since I have a animation that plays for 16 seconds, players could switch from weapons and still get high, I added a timer to keep the animation its just the function keeps going, this code seems to not work

if not self.Owner:GetActiveWeapon():GetClass( shroom ) then return end

Can you please post the actual full error?



[ERROR] file destination... attempt to index local 'ply' (a function value)

or

[ERROR] file destination... attempt to index local something else (a function/nil value)


The EXACT error. Do not redact anything; you are taking away the important parts.



[ERROR] addons/drugs/lua/weapons/weapon_base/shared:170: attempt to index local 'ply' (a function value)
 1. GetHigh - addons/drugs/lua/weapons/weapon_base/shared:170
  2. unknown - addons/drugs/lua/weapons/weapon_base/shared:228


170



if ply:GetNetworkedFloat("durgz_weed_high_end") && ply:GetNetworkedFloat("durgz_weed_high_end") > CurTime() && ply:GetNetworkedFloat("durgz_weed_high_end") - transition_time < CurTime() then


228 - Primary fire function



GetHigh();


both code where shown above, nothing new in particular.

What’s this: local ply = Entity? Why do you need that? You could try removing that line and changing GetHigh() in PrimaryAttack to GetHigh( self.Owner ).

You should actually put the player’s entity as the first argument of the function… and remove local ply = Entity because Entity = nil…

That’s pretty much what I just said but yeah, that’s what he should do.

local ply = Entity //I’ve done this after a point to speed up the process, I have also done self.player, self.entity ect… I didn’t always have it just added it to speed up the process. Same error regardless, but anyways thank you.

[editline]10th July 2014[/editline]

I’ll get back to you all if it works

[editline]10th July 2014[/editline]

Okay now I knew calling it would leave me with the same exact error just different words… Blah, I think your idea on the self.owner might work, but not within the GetHigh method



[ERROR] addons/drugs/lua/weapons/weapon_base/shared:170: attempt to index global 'Entity' (a function value)
 1. GetHigh - addons/drugs/lua/weapons/weapon_base/shared:170
  2. unknown - addons/drugs/lua/weapons/weapon_base/shared:228


[editline]10th July 2014[/editline]

the problem (from what I am seeing) isn’t in the primary fire, or even with the code itself, its just the prefix, i’m new with lua, I don’t know any of the names for things, but the thing befor the getnetworkfloat and setnetworkfloat is whats fucking it up, becuase when I did it in k, v pairs and put the prefix as v it all worked, but it requires a table which I used all the players as… LocalPlayer() is also = to nil … Any idea?

Doing that isn’t going to speed anything up, it’s just going to give you errors. In your GetHigh function, you have ‘ply’ in the arguments. By using GetHigh( self.Owner ) in PrimaryAttack like I suggested, your using that argument and now making ‘ply’ the owner of the weapon. In your original code, you didn’t supply GetHigh with the player/entity it needed to run. Additionally, you pretty much overrided ply with the ‘local ply = Entity’ line so it wouldn’t have worked even if you did supply it with a player. So, to fix your issue you would need to do pretty much what KokoNum and I suggested.



local function GetHigh( ply ) // I have taken the ply out put in other things same difference, I have done SWEP: infront of it and I have taken away local, ofcourse I haven't done everything with a different combination
	local lastingeffect = 60;
	local transition_time = 6;
	
	if !IsValid(ply) then return end

	if ply:GetNetworkedFloat("durgz_mushroom_high_end") && ply:GetNetworkedFloat("durgz_mushroom_high_end") > CurTime() && ply:GetNetworkedFloat("durgz_mushroom_high_end") - transition_time < CurTime() then
		--set the high start in such a way to where it doesn't snap to the start time, goes smoooothly.
		local set = CurTime() - ( ply:GetNetworkedFloat("durgz_mushroom_high_end") - CurTime() );
		ply:SetNetworkedFloat("durgz_mushroom_high_start", set);
			
	--if you're not high at all
	elseif( !ply:GetNetworkedFloat("durgz_mushroom_high_start") || ply:GetNetworkedFloat("durgz_mushroom_high_end") < CurTime() )then
		ply:SetNetworkedFloat("durgz_mushroom_high_start", CurTime());
	end
		
	--high is done
	local ctime;
	if( !ply:GetNetworkedFloat("durgz_mushroom_high_end") || ply:GetNetworkedFloat("durgz_mushroom_high_end") < CurTime() )then
		ctime = CurTime();
	--you're already high on the drug,  add more highness
	else
		ctime = ply:GetNetworkedFloat("durgz_mushroom_high_end") - lastingeffect/3;
	end
	ply:SetNetworkedFloat("durgz_mushroom_high_end", ctime + lastingeffect);
end




function SWEP:PrimaryAttack()
				DURGZ_LOST_VIRGINITY = true;
				GetHigh( self.Owner ); // I used to have it as DoHigh, same difference...
end


As you may see, I added a little check to see whether the player entity is valid using ‘if !IsValid(ply) then return end’. This will just make sure the code won’t run if there’s no player given or if the player isn’t valid.

Try what I just gave you there, it should work…

Entity:GetNetworkeFloat() is a deprecated function. You should be using Entity:GetNWFloat() instead. The same with Entity:SetNetworkedFloat(), use Entity:SetNWFloat()

yea, I have tryed it with just ply too alone, but it always ends up as a nil, I didn’t have the if !IsValid(ply) then return end though, i’ll try it out

[editline]10th July 2014[/editline]

that wouldn’t make any difference right? Its just apparently going to be removed in a latter release, but thats not whats creating the errors.

[editline]10th July 2014[/editline]

Wow, I really don’t understand how adding a simple is valid would fix it, i’m taking it as it made it exist? Anyways thank you so much honestly though, I really appreciate it!

[editline]10th July 2014[/editline]

One last thing, since I have a animation that plays for 16 seconds, players could switch from weapons and still get high, I added a timer to keep the animation its just the function keeps going, this code seems to not work

if not self.Owner:GetActiveWeapon():GetClass( shroom ) then return end


Thank you

-snip-

[lua]if self.Owner:GetActiveWeapon():GetClass() ~= “shroom” then return end[/lua]