Jump to content

Function in a timer bad argument


Markeloff

Recommended Posts

So, I want to know how to solve getting debug errors about expected element at argument 1, got nil. Actually, this happens to be everytime I use a timer containing a whole function in a function.

I know source isn't defined in the function inside this timer but doesn't every function have 'source' as argument by random?

So even when I tried to put the argument source in the function but the same problem. I solved this by excluding the function from being inside the timer but I need to know how to solve it this way.

  
function CheckingOnLogin() 
setTimer ( function() 
if isPlayerInSafeZone(source) then 
outputChatBox(getPlayerName(source).." logged in and in safe zone",root,255,0,0) 
setElementData(source,"isPlayerInSafeZone",true) 
toggleControl (source, "fire", false) 
toggleControl (source, "aim_weapon", false) 
else 
outputChatBox(getPlayerName(source).." logged in and not in safe zone",root,255,0,0) 
end 
end, 5000, 1 ) 
end 
addEventHandler("onPlayerLogin",root,CheckingOnLogin) 
  

Link to comment

try this

function CheckingOnLogin() 
    setTimer ( function(source) 
        if isPlayerInSafeZone(source) then 
            outputChatBox(getPlayerName(source).." logged in and in safe zone",root,255,0,0) 
            setElementData(source,"isPlayerInSafeZone",true) 
            toggleControl (source, "fire", false) 
            toggleControl (source, "aim_weapon", false) 
        else 
            outputChatBox(getPlayerName(source).." logged in and not in safe zone",root,255,0,0) 
        end 
    end, 5000, 1, source ) 
end 
addEventHandler("onPlayerLogin",root,CheckingOnLogin) 

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...