Timer.Simple "p" nil Value :( Pls Help me to fix it
14 replies, posted
It Timer.Simple make error
[code]timer.Simple(0.5,function(p)
p:SetPos(MenuPos.pos-(p:EyePos()-p:GetPos()));
end,p);[/code]
Full Code
[code]function JB:PlayerSpawn(p)
p:ConCommand("fov_desired 90")
p.Crouch = false;
if (p:Team() < 3) then
p:GodDisable();
p:SetColor(Color(255,255,255,255));
p:UnSpectate()
p:SetMoveType(MOVETYPE_WALK);
p:SetHealth(100);
p:SetArmor(0);
p:SetRunSpeed(250);
p:SetWalkSpeed(180);
p:SetNoDraw(false)
p:SetModel(JB:TranslateModel((p.character or JB.Characters.Prisoner[1]).model));
(p.character or JB.Characters.Prisoner[1]).OnSpawn(p);
p:Give("jb_knife");
p:Give("jb_hands");
p:StripAmmo();
p:GiveAmmo(500,"SMG1");
p:GiveAmmo(500,"Pistol");
elseif (p:Team() == TEAM_GUARD_DEAD or p:Team() == TEAM_PRISONER_DEAD or p:Team() == TEAM_SPECTATOR) and p.character then
p:Spectate( OBS_MODE_CHASE );
p:ConCommand("jb_spectate_switch_plus")
p:SetMoveType( MOVETYPE_OBSERVER );
p:SetNoDraw(true)
elseif not p.character then
p:SetTeam(TEAM_SPECTATOR);
p:SetMoveType(MOVETYPE_OBSERVER);
p:SetNotSolid(true);
p:SetPos(MenuPos.pos-(p:EyePos()-p:GetPos()));
p:SetAngles(Angle(0.403056, 90.340294, 0));
timer.Simple(0.5,function(p)
p:SetPos(MenuPos.pos-(p:EyePos()-p:GetPos()));
end,p);
p:Freeze(true);
p:SetNoDraw(true);
p.character = nil;
end
end[/code]
pls tell me how to fix it :(
What's the error/ which line gives you an error/ can you paste the console error?
[editline]30th March 2013[/editline]
Also, I don't think you need to pass p into your timer if you're creating it in the function that p is passed to.
[img]http://img46.imageshack.us/img46/457/afqwfqwfv.png[/img]
it error line 71
[code]timer.Simple(0.5,function(p)
p:SetPos(MenuPos.pos-(p:EyePos()-p:GetPos()));
end,p);[/code]
Sorry for my bad english :<
[QUOTE=aoa3005;40094417][img]http://img46.imageshack.us/img46/457/afqwfqwfv.png[/img]
it error line 71
[code]timer.Simple(0.5,function(p)
p:SetPos(MenuPos.pos-(p:EyePos()-p:GetPos()));
end,p);[/code]
Sorry for my bad english :<[/QUOTE]
[code]timer.Simple(0.5,function()
p:SetPos(MenuPos.pos-(p:EyePos()-p:GetPos()));
end);[/code]
O.o
[QUOTE=Ludicium;40094515]...[/QUOTE]
Robotboy is right
Check this out: [URL]http://lua-users.org/wiki/ScopeTutorial[/URL]
How can you reference p when it wasn't passed to the function though.
[QUOTE=Ludicium;40094577]How can you reference p when it wasn't passed to the function though.[/QUOTE]
p is accessible from the timer function as an upvalue.
Yeah but we still don't know how he declared his code, but I guess I am wrong, thanks for the lesson.
[QUOTE=Ludicium;40094619]Yeah but we still don't know how he declared his code, but I guess I am wrong, thanks for the lesson.[/QUOTE]
Look at the first post
[QUOTE=Willox;40094620]Look at the first post[/QUOTE]
The timer declaration is taken out of context.
It's within the block of full code, just use ctrl+f and you'll see it.
Oh well, I was thinking about this all the wrong way, didn't see it. I really feel dumb now. Feel free to give me the dumbs.
[QUOTE=Robotboy655;40094484][code]timer.Simple(0.5,function()
p:SetPos(MenuPos.pos-(p:EyePos()-p:GetPos()));
end);[/code][/QUOTE]
it work it work
thank you very much :)
You can't pass arguments with timer[PHP][/PHP]s since gmod13 update.
Sorry, you need to Log In to post a reply to this thread.