Jump to content

help plis :( expected element


Jacobob14

Recommended Posts

I don't know why give me this error the console

http://prntscr.com/8zjw7m

help me plis

  
function chase_move (ped, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz) 
    if not ped then return end 
    if (isElement(ped)) then 
       if (getElementData ( ped, "status" ) ==  "chasing" ) and (getElementData (ped, "slothbot") == true) then 
           setTimer ( function() setPedWeaponSlot (ped, weap) end, 850, 1) -- this is the line of the error 
           end 
       end 
end 

Link to comment
  
function chase_move (ped, oldTx, oldTy, oldTz, oldPx, oldPy, oldPz) 
    if not ped then return end 
    if (isElement(ped)) then 
       if (getElementData ( ped, "status" ) ==  "chasing" ) and (getElementData (ped, "slothbot") == true) then 
           setTimer ( function(ped) setPedWeaponSlot (ped, weap) end, 850, 1, ped) -- this is the line of the error 
           end 
       end 
end 

setTimer has an argument for any arguments you want to pass to the function within the timer. Since ped does not not exist inside the scope of the timer, and so the function thinks ped is nil, even though it's in your code. That is why you utilise the 4th argument in setTimer. It allows you to pass anything into the function. In this case, we pass the variable ped into the timer so we're able to do something with it. If you don't pass the variable and try to access it, it will always return nil.

Link to comment
  • Moderators

As Noki said it is recommended to put the ped variable as argument, but it is most of the time able to work without. Since the function is inside the block that contains the previous variable ped. Yet do it always as arguments just to be sure.

But what is absolutely recommended: to validate elements after timer execution. I see a lot of people don't doing it, because they think it is not required. As scripter you want 0 warnings/errors in your code, because they are another written line in your server logs. Which you want to keep low to de-increase the load and operation time of your machine.

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...